This post’s purpose is to find the fundamental inextricable
chord that connects almost or even all the design pattern under the bright blue
sunny sky. The fundamental high level
mission or goal of the gamut of GOF Design Patterns are giving much needed flexibility, loose coupling and resilience to code and
its sub structures.
>Introducing flexibility during static & runtime (aka
Dynamic Flexibility):
Polymorphic interface are the key
for this type of flexible systems. Let’s
break this into nuts and bolts, and then smooth the surfaces by refinement. Interfaces(C#/JAVA) are contracts that lay boundaries or
signature of methods/functions. This is akin to an abstract class with pure
virtual/abstract methods. Modern programming languages have developed a special
keyword that builds semantics behind them. That said and out of the way, we
need to prove why using interface are dynamically flexible? Any line of code
that has a “new” (JAVA/C#) keyword is
prone for hardcoding the concrete class on either side of the equation. This
is a humongous blunder and works against the flexibility of the code. Reminds
me of the OOPS principle – “programming
to interface rather than implementation”. WHY? When one puts concrete
classes on the left side of the equation, then one cannot have the flexibility
to change or switch the variable in context with other types of same nature. We
introduce an inevitable, deliberate constraint.
Caffeine cup = new Caffeine () ;
ICaffeine cup = new Caffeine () ;
On the other hand if we follow the rule “programming to interfaces”, i.e., left side of the equation has a polymorphic interface. Now this allows as swapping during run time any other similar matching type. Popular examples are Strategy, Factory Method, Abstract Factory, Decorator, State, Composite, Command, Observer etc.
On the other hand if we follow the rule “programming to interfaces”, i.e., left side of the equation has a polymorphic interface. Now this allows as swapping during run time any other similar matching type. Popular examples are Strategy, Factory Method, Abstract Factory, Decorator, State, Composite, Command, Observer etc.
>Introducing flexibility during post production without redeployment:
I
am not going to elaborate much on this front, as I have already covered in my
previous blog post about IOC/DI. Please refer the post IOC/DI
– From a Manager’s Perspective.

No comments:
Post a Comment