Header Ads Widget

C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming Tutorial


C-sharp-design-patterns-tutorial-for-beginners


We will discuss these following issues.

 

1 – What is C# Design Pattern? 

2 – Types of Design Pattern?

3 – Creational Design Pattern?

4 – Structural Design Pattern? And

5 – Behavioral Design Pattern?

6 – Conclude Disadvantages of Design Pattern

 

1 – What is Design Pattern

Design patterns are reusable solution to typical software design issues,

 

that arise frequently in real-world application development.

patterns are employed by developers to tackle challenges in their individual designs.

understanding design patterns is more important than memorizing their classes methods and attributes.

individual needs and difficulties influence pattern selection and uses among numerous design patterns.

 

2 – Types of Design Pattern

 

There are three types of design patterns available,

 

Creational design pattern

 

Structural design pattern and

 

Behavioral design pattern

 

3 – Creational Design Pattern?

 

The creational design patterns deal with object creation and initialization.

 

The creational design pattern gives the programmer more flexibility in deciding which objects need to be created for give for a given case.

 

we have five types of design patterns in this

 

Abstract factory,

 

Builder,

 

Factory method,

 

Prototype and

 

Singleton

 

Discuss each of them in detail

 

Abstract factory

 

The abstract factory design pattern allows you to create families of linked items without having to declare their classes.

 

Builder pattern

Builder is a design pattern that allows you to build complicated objects in stages.

 

This patterns enables you to create many types of representations of an object while using the same creation code.

 

Factory method

A factory method is a creational design pattern that provides an interface for creating objects in superclass,

 

while allowing subclasses to choose the type of object created

 

Prototype

Prototype pattern is a design pattern that allows you to imitate existing objects without making your code land on their classes.

 

The prototype patterns provides a basic interface for working with all objects that permits cloning to the client code.

 

Singleton.

 

The singleton pattern ensures that a class has only one instance while also giving a global access point to that instance.

 

 

4 – Structural Design Pattern

 

The structural design pattern is basically used to manage the structure

of classes and interfaces.

 

as well as manage the relationship between the classes.

 

we have seven types of design patterns in this

 

Adapter

 

Bridge

 

Composite pattern

 

Decorator pattern

 

A cat pattern

 

Fly weight pattern and

 

Proxy pattern

 

let's discuss each of them in detail

 

Adapter

 

The appendage design pattern is a structural design pattern,

 

that allows particulars with clashing interfaces to work with one another.  

 

we use this pattern to reuse many existing subclasses that lacks common functionality that cannot be added to the super class

 

Bridge

 

this pattern is a structural design pattern that allows you to split large class or a collection of related classes into two independent hierarchies abstraction and implementation

 

Composite pattern

 

composite is a structural design pattern that enables you to organize parts into three structures,

 

and manipulate them independently of one another,

 

the composite pattern provides two basic element kinds with a shared interface

 

simple leaves and complex containers.

 

Decorator

 

Decorator is a structural design pattern that allows objects by wrapping them in special wrapper object.

 

This pattern uses the decorative technique to add extra behaviors to objects without disrupting the code that utilizes them.

 

Facade

 

forcad is a structural design pattern that simplifies complex libraries frameworks and class interfaces.

 

When you require a simple but limited interface to a complicated subsystem we use the phycat pattern.

 

proxy pattern

 

Proxy is a structural design pattern that enables you to substitute an item.

 

A proxy control access to a source object allowing you to do actions before or after the request.

 

5 – Behavioral Design Pattern

 

The behavioral design pattern deals with communication between classes and objects.

 

That means if you want to change the geste of a class and again you want it to affect other classes of the design as well.

 

we have 10 types of design patterns available in this

 

Chain of responsibility

 

Iterator

 

Memento

 

Speed

 

Template method

 

Command

 

Mediator

 

Observer

 

Strategy and

 

Visitor

 

 

Discuss them in detail

 

Chain of responsibility

 

A behavioral design pattern called the chain of responsibility allows you to pass requests along the chain of handlers.

 

When a request is received each handler determines whether to process it or send it to the next handler in the chain.

 

Iterator

 

Iterator is a behavioral design pattern that allows you to traverse components of a collection without revealing the representation below that is list stack tree etc.

 

Iterators can be used to traverse composite trees

 

Memento

 

Memento is a behavioral design pattern that saves and restores an object prior straight.

 

Without revealing its implementation when you need to take pictures of an object's state in order to store it to a previous state we use memento pattern .

 

State pattern

 

state is a behavioral design pattern that allows an entity to change its behavior in response to the changes in its internal state.

 

it appears that the object's class has changed.

 

Template pattern

 

Template method is a behavioral design that lets subclasses.

 

Alter steps of an algorithm without changing its structure.

 

We use the template method to allow customers to extend specific types of an algorithmnot the entire method or its structure

 

Command pattern

 

Command is a behavioral design pattern that turns a request into a standalone object.

 

This transformation supports unachievable operations and passing request as method argument.

 

Mediator

 

Mediator is a behavioral design pattern that reduces object dependency to collaborate the objects must first communicate to a mediator object.

 

Observer pattern

 

Observer is a behavioral design pattern that allows you to establish a subscription mechanism to allow alert numerous objects about an event that occur to the item being observed.

 

when some objects in your app must cover others for a limited time or in specific circumstances we use this pattern.

 

Strategy pattern

 

Strategy is the behavioral design pattern that allows you to construct a family of algorithms.

 

Classify them and make them object interchangeable

 

When you have a bunch of similar classes that just differ in how they perform some behavior then we use the strategy pattern.

 

Visitor

 

The visitor pattern is a behavioral design pattern that allows you to decouple algorithms from the objects they act on.

 

When you need to perform an operation on all elements of a complicated object structure we use the visitor.

 

 

Let's conclude

 

This tutorial with some advantages of design patterns

 

First up abstract factory classes are frequently based on set of factory methods although the method on these classes can also be composed using prototype.

 

Next up to reduce ram we can use flyweights to construct shared composite tree leaf nodes

 

 

Finally you can treat a visitor as a powerful version of the command pattern,

Post a Comment

1 Comments