File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Which Pattern to select ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Which Pattern to select ?" Watch "Which Pattern to select ?" New topic
Author

Which Pattern to select ?

Arul Prasad
Ranch Hand

Joined: Jan 20, 2005
Posts: 57
Consider my case and tell me which pattern will be a good solution.

I have one entity called EntityA

which is consist of Section A , B , C , D , E.


Under the dynamic cases these sections will be included, for example

Case 1
Entity 1 consist of Section A , C, D, E.

Case 2

Entity 1 consist of Section A , B , C, D, E.

..etc

In each section i have many fields to fill and i have to do the following operations

1) validate each sections

2) save the data for the each sections.


[ April 23, 2008: Message edited by: Arul Prasad ]

With Regards<br />Arul
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Why do you think that there has to be a design pattern for this?
I dont know whether the solution to this is a design pattern but your problem can be respresented as the following:

1) Section: An interface defining the methods on a section. This can have a validate method.
2) Section implementations: Different implementations for the Section interface. You call them A,B,C, ... in your description.
3) Entity A: This contains a list of the different implementations of Section.

In the above, Entity A is a composition of different sections but does not follow the Composite pattern as such.
[ April 23, 2008: Message edited by: Nitesh Kant ]

apigee, a better way to API!
Arul Prasad
Ranch Hand

Joined: Jan 20, 2005
Posts: 57
Thanks, Why can't we go for an Decorator pattern ..?

because i have sections like A,B,C,D,E.

but all the data maniupulation,validation i have to do it for all the sections or gorup of combined sections based on my runtime condtions.

Wiki Decorator
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Arul:
but all the data maniupulation,validation i have to do it for all the sections or gorup of combined sections based on my runtime condtions.


Typically, there is a one to one mapping between a decorator and a type of instance(an interface implelmentation)
In your case you have a combined set of sections and the validations are done for the set of sections. This would really not be a decorator for sections but it may qualify as a decorator for the holder of these sections(EntityA as you call it)
For this to be a decorator, you must have a base interface and a decorator interface that extends the base interface.
The hierarchy of decorators and the main component can exist independently.
In a nutshell, the idea of having a decorator is to add functionality at runtime to a core component that will be totally unaware of the presence of a decorator.
So, if there exists a component A, i may have Decorators D1, D2, D3 ... that i can apply according to the requirements.

A related pattern can be a Facade, this is single layer to wrap a complex business operation that spans across various entities.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Arul Prasad:

In each section i have many fields to fill and i have to do the following operations

1) validate each sections

2) save the data for the each sections.





And what prevents you from doing something along these lines?


[ April 28, 2008: Message edited by: Peer Reynders ]
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Hi Peer,
Yeah thats exactly what i suggested !
Actually, arul wanted to know whether any design pattern can be applied to this problem or not.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Nitesh Kant:
Yeah thats exactly what i suggested !


So you did!
In my haste I probably scanned past your first suggestion.
However sometimes a separate view/representation of the same solution can get the point across.
My pseudo Java version is certainly more verbose.

arul wanted to know whether any design pattern can be applied to this problem or not.


In my opinion neophytes can get a bit "pattern mad". Study, know and practice the Object Oriented Design Principles and apply patterns gently. Many patterns are simply the result of the application of OOD principles to a set of commonly recurring problems. So ultimately competence in OOD principles is much more generally useful than memorizing a bunch of patterns.
Arul Prasad
Ranch Hand

Joined: Jan 20, 2005
Posts: 57
Thanks a lot,

Peer Reynders , Nitesh Kant.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Which Pattern to select ?
 
Similar Threads
six coins
long post IBM.158
need help on mock question
Anyone have any sample test for jobs?
Refreshing only part of the screen in jsp