In: Computer Science
Discuss the overlap that you see in these last four GRASP patterns. Or, if you don't see overlap, then describe how they are different.
- Polymorphissm
- indirection
- Pure Fabrication
- Protected Variations
1. polymorphism :-
->polymorphissm is used to dynamically handle similar object
types.when somethings like function , variable has a same name but
different defination we will use polymorphism.
->it is also used to simulate plugable software type
system.
-> it eliminate conditional statement.
-> In OO languages polymorphism is tied up with
substitutability.
-> for that we design methods and we write client code that can
operate on a set of types.
2.indirection :-
->it's avoid coupling between objects by separating them with an
intermediate objects.
->Adapter is going to allow system objects to interact with
external interfaces dynamically.
->example using GOF : Adapter , bridge , facade , observer
,mediator.
-> diffrence from pure fabrication is that low couoling is in
indirection.
3.Pure fabrication :-
->if we creates object and that feel a need that has no real
world counterpart , this is an
example of pure fabrication.
->And example is object that would only save the information ,
update information or delete information.
->example using GOF pattern is Adapter , command , strategy
.
->information experts cause high coupling.
4.Protected variation :-
-> how do you design objects so that variation doesn't have bad
effects ?
solution :- look for elements with coupling that may change and
surround them with a stable interface.it is calles protected
variation.
example :- suppose we have class sale,and it contains
date,items,itemprice,purchesamount and calculatetax. we have one
member is calculatetax which will change in future so we want to
protect using protected variation. so we will use adapter. first we
will create an interface call calculatetax. in which we slap
diffrent tax using adapter.