Welcome to the first blog in the Design Patterns series.
I have found a lot of very good explanations about design patterns on the internet.
But in this particular series I would reflect on my experiences and try to explain how these patterns can be applied to requirements in PLM Domain.
The PLM application space already has a lot of rich applications like Siemens PLM Teamcenter, Dassault System Innovia, PTC Windchill etc. However many a times one needs to develop solutions around them given the vastness of the domain.
I hope this series will help a bit to those developers.
In this post we will see one example of Decorator Design Pattern applied to Part Packaging requirement.
A typical requirement about a part is that it should be packaged for shipping. The part itself has some basic behavior for packaging.
However there are different ways it needs to be packaged depending on the situation. Typical packages could be based on transportation Air/Sea,/Land or based on weather conditions Hot/Humid/Cold/Dry etc. The packaging method will vary from one unit to another.
Design Implications
a. We have basic packaging behavior for all types of packaging. Let's call the method packMe()
b. We cannot extend the part, neither we can make it implement different type of interface with the same method packMe()
c. We would know what type of behavior is needed only at run time.
Design Pattern
Decorator Design Pattern is suitable in this cases.
Decorator is used to extend (decorate) the functionality of a certain object statically, or in some cases at run-time, independently of other instances of the same class. It achieves this through wrapping an instance of the basic class by the basic decorator. Decorator and the basic class would implement the same interface. The decorator will then be extended in specific classes to provide the additional behavior.
The client program shows how these decorators are invoked run time.
Thanks for visiting the page.
Your views and comments are welcome!
Decorator is used to extend (decorate) the functionality of a certain object statically, or in some cases at run-time, independently of other instances of the same class. It achieves this through wrapping an instance of the basic class by the basic decorator. Decorator and the basic class would implement the same interface. The decorator will then be extended in specific classes to provide the additional behavior.
IPart is the interface with a method packMe()
GeneralPart class implements IPart and provides common behavior for packMe().
PackDecorator abstract class implements IPart as well as contains a instance variable of type IPart.
packMe() implementation of this class calls packMe() of the instance variable.
RoadLinePackDecorator, AirFreightPackDecorator and ShipPackDecorator all extend to PackDecorator and provide special behavior for packMe(). All of them call the packMe() method of super.
The client program shows how these decorators are invoked run time.
Thanks for visiting the page.
Your views and comments are welcome!
