background img

Trendy News

Grammar behind Design Patterns

Grammar behind Design Patterns
It has been found out that mostly the engineers and the designers get influenced by the business jargons thrown by the customer and because of the lack of knowledge about the business jargons and domain finds the problem to be daunting and fails to understand the same.
Now this is where the basic difference lies….. If a person thinks as a layman, he might find the problem daunting because of the scale and ambiguity …But if the person is an engineer or a designer who understands the basic fact that "Technically every thing in this world is a system which is nothing more than structure and behavior".. then the same daunting problem looks extremely simple.
This is the first best practice that we share with any prospective designer or an architect …. "For any good designer or an architect, every thing in this world is a technical system, which in turn is made up of structure and behavior and hence they should never get influenced by the business jargons thrown by the customer."
The business case that I am describing next will help us understand the importance of this best practice.
Lets say there is a Bank named ABC based out of the US and this Bank is offering traditional banking services to its customers in the United States. Traditional banking services means the usual services offered by a bank in a manual or a non automated manner. Also there are 1000 banking professionals working in the bank using which the bank is offering its services in a non automated way.
Over a period of time, the customers of the bank are fed up with these non automated services and they start demanding "Technology Based Banking" … ie they want to access most of the services of the bank through all the technical gizmos like the PDA, Handheld devices, Internet, Information Kiosks, ATMs etc .
Now lets say you are the decision maker of the Bank lets say the CEO of the bank … how will you handle a crisis like this ?
ost of the times peoples are stunned because of the magnitude of the problem … they start saying that we will first do a feasibility study, followed by a risk mitigation planning ete etc. This happens because they get trapped into all the banking jargons that is mentioned in the above business case.
Now let us understand the same problem from a systemic point of view.
Do we agree that every Bank is a technical system as well with behaviors and enabling structure?
Yes let us understand technically a Bank is a system wherein this bank is currently offering a behavior called traditional banking and the 1000 banking professionals who are working in this bank is the enabling structure which is giving this behavior.
Now over a period of time , the customers start demanding a new behavior from the Bank(System) called "Technology Banking". So I hope the readers will realize that this is a simple problem of behavioral change wherein there is an already existing system with some structure and behavior and now there is a need for a new behavior from the same system.
So what are the ways in which this behavioral change can be handled?
let me repeat the same example of "My association with my Car" …. where in I as a Human being have the structures and behaviors defined by the class called as Human Beings. One fine day I come across a need of a behavior called as "Movement at 100 kmph" which is not supported by my base class [ie my body currently doesn't have an enabling structure which can enable my body to run at 100 kmph]. So what are the ways in which I can satisfy the need of a behavior which is not supported by my base class.
As you will realize …. one of the ways is to use an external system (Car) and get the need satisfied [Association]
While there the second option is to extend the structure of the existing system with a new new enabling structure which can incorporate the new behavior. [This is possible by extending the structure of a human being by permanently attaching a jet engine or a high powered motor or a engine on him].
Coming back to our original case…. The situation faced by the bank is similar to the situation faced by the Human body as they both face a simple problem of behaviorial change.
Hence there are two solutions for this problem
Associate with an external system to get this new behavior
Extend the existing bank with a new enabling structure to facilitate this new behavior.
The first option is nothing but outsourcing the technology related work to any technology service provider which could be any of the Indian TSPs like Infosys, Wipro, Polaris, TCS etc etc

The second option is to extend the company …lets the management of the bank decides to extend the bank by 20% ie they recruit 200 technology experts using which the new technology banking as a behavior will be delivered.
So there are two simple solutions … either the bank can outsource [Association] or extend [Inheritance].
Now think about the parameters that can help a person choose one of the two options ..
Or in other words
What are the parameters that should be true for Outsourcing to the best option?
and
What are the parameters that should be true for Extension to the best option?
As you all might be thinking about various parameters like
time, availability of resources, cost, security [IP Protection] etc etc.
Let us quickly understand each of these parameters and its repercussions…
Time - Time is a very important parameter which influences this decision. If technology banking as a behavior is needed immediately … then outsourcing may be a much better option as recruiting [recruitment and training ] may take a much longer time while on the other hand there are trained and readily available professionals who can quickly implement this behavior .
Availability of trained resources - This again can be an influential parameter .
Security [IP Protection] - If bank doesn't want to share its IP with the technology service provider, then the bank might take the decision of extending the company.
Cost - Cost can play a very critical role … but cost should not be associated with cheap labour. Let us understand Outsourcing and "Cheap labor" are two different issues and should be considered separately. This confusion is the courtesy the Indian IT Industry which has made "Outsourcing" and "Cheap Labor" synonymous.
Let us understand all of the above mentioned factors can influence the choice of decision , but there is one parameter which will clearly help us understand which option is a better way of handling this problem.
Ask yourself … what is the basic problem that we are trying to address ?
As we know .. this is a simple problem of behavioral change wherein there is a need for a extra behavior.
The moment we realize that it is a simple problem of behaviorial change …. don't you think that the first question that should hit our mind is
"Whether the change is a permanent change or a temporary/intermittent change?"
I hope you will realize this question will clearly give you an idea about the appropriate solution.
"A permanent behavioral change is a behavior which will always be used"
while "A temporary or intermittent behavioral change is a behavior which will not be used at all points of time."
The rule says …"If the change is a permanent change, then extension is a better way while if the change is either temporary or intermittent , the outsourcing is a better way of managing change".
This principle can also be understood as the principle of core and non core behaviors. One of the fundamental principles of any well designed system says … that "A system should not do anything more than its core behavior, else the enabling structure of the non core behaviors will become a liability on the system when these non core behaviors are not needed"
Core Behavior - Core Behavior is a behavior which is always used/needed and hence the enabling structure for these core behaviors will never become a liability on the system. While
Non Core Behavior - Non Core Behavior is a behavior which is not needed / used at all points of time and hence any enabling structure for these non core behaviors will become a liability on the system when these behaviors are not needed.
There are multiple design patterns which use the concept of core/ non core behaviors to derive a solution.
So very simply we can say …. if the change is permanent use extension else use outsourcing or association.
Extension of structure is technically called as Class Inheritance . The keyword class is prefixed as classes are static in nature and hence the user will realize that he is taking a static decision to manage change.
Outsourcing is a business word…. It is technically called as Object Composition. The key word Object is prefixed as Objects are dynamic in nature and hence the user will realize that he is taking a dynamic decision to manage change.
Although it is very simple to say that .. if the change is permanent use "Class inheritance" else use "Object Composition" but this may not be true in certain situations.
let us consider a situation
lets say the Bank ABC realizes that Technology Banking as a behavior is a permanent behavior and hence they extend the bank by 20% recruiting 200 TPs to implement this behavior. But immediately after recruiting these 200 TPs the bank realizes that these 200 TPs either don't have the right skills, or attitude or knowledge to deliver this behavior. Now what can the bank do ….. should they lay off these 200 TPs and recruit another 200 TPs with the right skills….. ask yourself .. how can they lay off … they have recruited them…
So now the bank has two options , either it can take these 200 TPs as liability and recruit 200 more TPs with the right skill or take these 200 TPs as liability and outsource the work.
So I can reframe my previous best practice to take into account the above mentioned scenario.
I can now say "Class Inheritance" should only be used
The change is permanent
We are very confident about the structure needed to implement this behevaior
If both of the conditions is not true … Class inheritance is not the right way of managing change making way for Object Composition.

Class Inheritance if not done the right way will build liability within the system while Object Composition will build [Two levels]flexibility within the system.
The first level of flexibility comes because of the association relationship where in the bank is given the flexibility to outsource whenever they want , paying only for the services delivered whenever needed.
While the second level of flexibility comes because of the common interface (polymorphism) implemented by all the outsourcing companies. 
Now ask yourself ….
Why is "Outsourcing" a very successful business paradigm wherein every business is trying to outsource its non core activities or behaviors?
Let us understand … Outsourcing [Object Composition] is a Flexible way of designing a system because of the two levels of flexibility that object composition provides.
So let me quickly summarize … Changes to a system can be managed either by Class Inheritance or Object Composition wherein Class Inheritance should only be used if the change is permanent and we are confident about the structure used to implement the changes. Object composition should be used if the two mentioned conditions is not true.
If the rules for Class Inheritance and Object composition is clear to the readers , then we are virtually covered 80% of core design patterns.
The following section shows how Class Inheritance and Object Composition becomes the building blocks of Core Design Patterns
Classification of Core Design Patterns
Core Design Patterns are best practices for designing highly flexible systems.
As we know flexibility as a parameter defines the adaptability of the system to various types of changes and there are three types of changes that can be possible within systems viz Structural Change, Behaviorial Change and Creational Change.
Hence design patterns can also be of three types viz
Structural Design Patterns
Behaviorial Design Patterns
Creational Design Patterns
Structural Design Patterns are best practices for designing highly flexible systems wrt structural changes.

Behaviorial Design Patterns are best practices for designing highly flexible systems wrt behavioral changes.
Creational Design Patterns are best practices for designing highly flexible systems wrt creational changes. Creational changes are specific to factory based systems.
Irrespective of the type of change that needs to be managed we know there are two ways of managing changes within systems ie Class Inheritance and Object Composition.
Hence every design pattern has a scope which could be either be "class scope" or "object scope" or both.
If the pattern uses "Class Inheritance" as a technique to manage change the pattern is considered to be of class scope while if the pattern uses "Object Composition" as a technique to manage change the pattern is of object scope.
It should not be surprising to find out that out of the 23 core design patterns , 20 design patterns are of object scope rest 3 patterns are of class scope. As object composition gives two levels of flexibility hence most of the patterns uses object composition to manage changes.
As flexibility is one of the very important parameters needed within software systems … most of the programming languages, tools, frameworks, IDEs etc are designed using these 23 design patterns and hence are some times called as the Core Design Patterns.
As Object Composition is nothing but simple association and polymorphism and s most of the design patterns is using Object Composition to incorporate flexibility …. Design Patterns at a very basic level is nothing but commonsensical use of association and polymorphism.
We know Polymorphism also can be of two types viz Controlled and UnControlled Polymorphism wherein Interfaces are used to implement UnControlled polymorphism while Abstract Classes with Non Abstract methods marked in a form that it cannot be over ridden are used to implement Controlled Polymorphism.
So technically speaking design patterns is all about association and interfaces / abstract classes.
I presume any one who is reading this topic will know how to write an interface / abstract class in any programming language.
Hence we should not bother about implementing a design pattern as deep down it will be either implemented as an Interface / Abstract Class.

0 comments :

Post a Comment

Popular Posts