Muhd Kamil Mohd Baki wrote:
> I would like to know your feedback on where is the best place to put
> helper methods. What I mean by helper methods is like a simple example
> below:
> 
> public boolean nameIsEquals( Name name, String text )
> {
>   return text.equals( name.name().get() );
> }
> 
> With this approach I can just pass anything that has a name and
> probably saves a few keystrokes, and avoid silent errors too.
> Sometimes I did text.equals( person.name() ) and missed the .get()
> part, there is no compilation error. Anyway, this can be avoided if I
> write unit test code first.
> 
> I am thinking of declaring it in the Name composite itself and provide
> a mixin for it. However, I believe there are better ways.

Well, it depends somewhat if this is to be used internally in the Name 
composite or by clients. If by clients you have a choice of putting it 
in the Name interface itself or something else. In SiteVision I 
sometimes added a pure helper delegation mixin to do this in order to 
not clutter the main interface too much. I.e. create interface/mixin 
"NameHelpers" with the stuff you need and add it to the Composite so 
that clients can use it, but not clutter the main Name interface. Many 
of these methods are usually such that they don't have anything to do 
with the domain itself, like Name, but are things which makes the 
Clients work easier and which you would typically put in a static class 
somewhere. By placing them in a mixin on the composite they are easier 
to access, especially if the object is accessed through scripting(!!! 
VERY IMPORTANT!!!).

/Rickard

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to