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 ]
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.
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.
Joined: Aug 19, 2005
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.