Design Pattern

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

DESIGN PATTERNS IN C#

What is Design Pattern in .Net?


• Design Patterns in the object oriented world is a reusable solution to
common software design problems that occur repeatedly in real-world
application development.
• It is a template or description for how to solve problems that can be used in
many situations.

Which are the Types of Design Pattern?


• Creational Patterns: It mainly deals with creation of Objects and Classes.
Types of creational patterns are:
1. Factory Method : Creates an instance of several derived classes
2. Abstract Factory : Creates an instance of several families of classes
3. Builder : Separates object construction from its representation
4. Prototype : A fully initialized instance to be copied or cloned
5. Singleton : A class in which only a single instance can exist

• Structural Patterns: It deals with Class and Object Composition.


Types of Structural patterns are:
1. Adapter : Match interfaces of different classes.
2. Bridge : Separates an object's abstraction from its implementation.
3. Composite : A tree structure of simple and composite objects.
4. Decorator : Add responsibilities to objects dynamically.
5. Flyweight : A fine-grained instance used for efficient sharing.
6. Proxy : An object representing another object.

• Behavioral Patterns: It deals with Class and Object communication. That


means they are concerned with the communication between class and
objects.
Types of Behavioral patterns are:
1. Chain of Responsibility : A way of passing a request between a chain of
objects.
2. Command : Encapsulate a command request as an object.
3. Interpreter : A way to include language elements in a program.
4. Iterator : Sequentially access the elements of a collection.
5. Mediator : Defines simplified communication between classes.
6. Memento : Capture and restore an object's internal state.
7. Observer : A way of notifying change to a number of classes.
8. State : Alter an object's behavior when its state changes.
9. Strategy : Encapsulates an algorithm inside a class.
10. Visitor : Defines a new operation to a class without change.
11. Template Method : Defer the exact steps of an algorithm to a subclass.

Which are the key Benefits of using Design Patterns?


• They give the developer a selection of tried and tested solutions to work with.
• They are language neutral and so can be applied to any language that
supports object-orientation.
• They aid communication by the very fact that they are well documented and
can be researched if that is not the case.
• They have a proven track record as they are already widely used and thus
reduce the technical risk to the project.
• They are highly flexible and can be used in practically any type of application
or domain.
ARCHITECTURAL PATTERNS IN C#
Goals of Architecture

There are various goals of architecture,


• Create outline or skeleton to implement a product
• Hide detail and inner complexity and show the structural detail
• Help developer to utilize common components or code
• Loosely coupled design of product
• Reduce redundant code by creating reusable components or library
• Solve well known issues which occurred while designing any application
• Easy to maintain product in support phase
• Satisfy the end user by providing cutting edge solutions
• Easy to adapt any business changes in future
There are various objectives and goals which we can achieve from good
architecture.

Architecting Principals

There are some key design principals which help to achieve a good architectural
product and they are,

• Separation of concern
Separation of concern is nothing but a style of implementation of code
or business logic and UI in a clean way so that both should not mix
together. It means business concerns or other key logic should be in a
separate layer or file from UI design.

• Single Responsibility
As the name suggests, each module or component should be
responsible for one and only one task.

• Least Knowledge
It means one component should not know the detail of other
components.

• Do not Repeat
It means the same functionality should be repeated in multiple
components. One functionality should be in one component.

• Minimize the Design


Only design what is required for the application and do not try to
reinvent the wheel if something is already available. Try to use time
tested reusable components if possible. This will minimize the testing
effort and time for bug fixing which in turn is cost effective development
and will meet the deadline easily.

The idea of these design principals is to hide the complexity of modules


by componentizing the solution and providing easily adoptable
components or functions which we may reuse with other applications as
well. For example, distribute different areas of concern into different
components such as Data Access, Business Logic, Exception Handling
Mechanism, Email or SMS handling, File Operation, Services etc.

You might also like