Design Patterns
1) Creational Patterns
• Abstract Factory:- Creates an instance of several families of classes
• Builder: - Separates object construction from its representation
• Factory Method:- Creates an instance of several derived classes
• Prototype:- A fully initialized instance to be copied or cloned
• Singleton:- A class in which only a single instance can exist
2) Structural Patterns
2) FAÇADE pattern
Façade pattern sits on the top of lot of subsystems and makes access easy to interfaces of these
subsystems. Basic purpose of Façade is to make interfacing between many modules and classes
manageable.
Above is a simple live application of a Façade class. In this, we have four subsystems:-
• Customer
• Product
• Payment
• Invoicing
3) Singleton pattern
“web service” and “remoting” is that “web service” can be consumed by clients who are not
.NET platform. While remoting you need the client to be .NET compliant. Regarding the speed
issue “Remoting” is faster than “Web Services”. So when you are choosing between “Web
services” and “Remoting” keep the cross platform issue and the speed issue in mind.
1) Creational Patterns
• Abstract Factory:- Creates an instance of several families of classes
• Builder: - Separates object construction from its representation
• Factory Method:- Creates an instance of several derived classes
• Prototype:- A fully initialized instance to be copied or cloned
• Singleton:- A class in which only a single instance can exist
2) Structural Patterns
• Adapter:-Match interfaces of different classes.
• Bridge:-Separates an object’s interface from its implementation.
• Composite:-A tree structure of simple and composite objects.
• Decorator:-Add responsibilities to objects dynamically.
• Façade:-A single class that represents an entire subsystem.
• Flyweight:-A fine-grained instance used for efficient sharing.
• Proxy:-An object representing another object.
3) Behavioral Patterns
• Mediator:-Defines simplified communication between classes.
• Memento:-Capture and restore an object's internal state.
• Interpreter:- A way to include language elements in a program.
• Iterator:-Sequentially access the elements of a collection.
• Chain of Resp: - A way of passing a request between a chain of objects.
• Command:-Encapsulate a command request as an object.
• State:-Alter an object's behavior when its state changes.
• Strategy:-Encapsulates an algorithm inside a class.
Factory Vs Abstract Factory
Factory method uses inheritance to decide which object has to be instantiated
Abstract factory uses delegation to decide instantiation of an object
We can say Abstract factory uses factory method to complete the architecture. Abstract Factory is one level higher in abstraction over Factory.
1) Factory Patterns
• The actual product section i.e.“Product” Class inherits from an abstract class “Abstract Product”.
• The creational aspect section i.e. “Concrete Creator” class which inherits from class "Creator”.
Some rules the client will have to follow who will need the “Product” object?
- He will never refer directly to the actual “Product” object but can refer the“Product” object using “Abstract Product” class.
- He will never use “New” keyword to create the “Product” object but will use the “Creator” class that in turn will use the “Concrete Creator” class to create the actual “Product” object.
Benefits from this architecture
All creational and initializing aspects are now detached from the actual client. As your creational aspect is now been handled in “Concrete Creator” and the client has reference to only “Creator”, so any implementation change in “Create Product” will not affect the client code. In short, now your creational aspect of object is completely encapsulated from the client’s logic.
2) FAÇADE pattern
Façade pattern sits on the top of lot of subsystems and makes access easy to interfaces of these
subsystems. Basic purpose of Façade is to make interfacing between many modules and classes
manageable.
Above is a simple live application of a Façade class. In this, we have four subsystems:-
• Customer
• Product
• Payment
• Invoicing
All the four modules when built at initial stage where built completely independent. The main
interaction between all these subsystems is customer-placing order. This functionality can be
attained by using all these subsystems, which involves complex interaction between them.
That is where FAÇADE comes in to action. We have built a FAÇADE called as
“FACADEORDER” which sits on the top of all these subsystem and fulfill our functionality.
3) Singleton pattern
Singleton pattern ensures that a class has only one instance and provides a global point of access to it.
Following are the three steps needed to implement singleton pattern in .NET:-
• First, create your class with static(Shared in vb.net) members.
Public class ClsStaticClass
Private static clsCustomer objCustomer
End class
This ensures that there is actually only one Customer object throughout the project.
• Second, define a private constructor to your class.
Note: - defining a private constructor to class does not allow a client to create objects directly.
• Finally provide a static method to get access to your singleton object.
4) Prototype pattern
_______________________________________________________________________
What is three-tier architecture?
The three-tier software architecture emerged in the 1990s to overcome the limitations of the twotier
architecture.
There are three layers when we talk about three-tier architecture:-
User Interface (Client/Application Layer):-
This is mostly the windows user interface or the Web interface but this has only the UI part.
Mid layer(Business Layer): -
Middle tier provides process management where business logic and rules are executed and can accommodate hundreds of users (as compared to only 100 users with the two tier architecture) by providing functions such as queuing, application execution, and database staging.
Data Access Layer: -
This is also termed by the famous acronym "DAL
Following are the three steps needed to implement singleton pattern in .NET:-
• First, create your class with static(Shared in vb.net) members.
Public class ClsStaticClass
Private static clsCustomer objCustomer
End class
This ensures that there is actually only one Customer object throughout the project.
• Second, define a private constructor to your class.
Note: - defining a private constructor to class does not allow a client to create objects directly.
• Finally provide a static method to get access to your singleton object.
4) Prototype pattern
Twist: - How to implement cloning in .NET? What is shallow copy and deep copy?
Cloning is achieved by using ICloneable of the System namespace. It has a “Clone” method, which actually returns the reference of the same copy. Clone method allows a Shallow copy and not a deep copy. In Shallow copy if you make changes to the cloned object it actually, changes on
the main object itself.
So how is deep copy achieved, by using “ISerializable” interface? So what you do is first serialize the object then deserialize back to a complete new copy. Now any changes to this new copy do not reflect on the original copy of the object, this is called as Deep copy.
_______________________________________________________________________
What is three-tier architecture?
The three-tier software architecture emerged in the 1990s to overcome the limitations of the twotier
architecture.
There are three layers when we talk about three-tier architecture:-
User Interface (Client/Application Layer):-
This is mostly the windows user interface or the Web interface but this has only the UI part.
Mid layer(Business Layer): -
Middle tier provides process management where business logic and rules are executed and can accommodate hundreds of users (as compared to only 100 users with the two tier architecture) by providing functions such as queuing, application execution, and database staging.
Data Access Layer: -
This is also termed by the famous acronym "DAL
What are the situations you will use a Web Service and Remoting in projects?
“Web services” uses “remoting” concepts internally. However, the major difference between“web service” and “remoting” is that “web service” can be consumed by clients who are not
.NET platform. While remoting you need the client to be .NET compliant. Regarding the speed
issue “Remoting” is faster than “Web Services”. So when you are choosing between “Web
services” and “Remoting” keep the cross platform issue and the speed issue in mind.

