Presentation is loading. Please wait.

Presentation is loading. Please wait.

Design Patterns Imran Rashid CTO at ManiWeber Technologies.

Similar presentations


Presentation on theme: "Design Patterns Imran Rashid CTO at ManiWeber Technologies."— Presentation transcript:

1 Design Patterns Imran Rashid CTO at ManiWeber Technologies

2 Outline Introduction to Design Patterns What is Gang of Four (GOF)?
Usage of Design Patterns Types of Design Patterns Singleton Pattern Decorator Pattern

3 Introduction to Design Patterns

4 Introduction to Design Patterns
Design patterns represent the best practices used by experienced object-oriented software developers Design patterns are solutions to general problems that software developers faced during software development These solutions were obtained by trial and error by numerous software developers Design patterns in object oriented world is reusable solution to common software design problems which occur again and again in real world app development "A pattern is a recurring solution to a problem in a context"

5 What is Gang of Four (GOF)?

6 What is Gang of Four (GOF)?
In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides published a book titled “Design Patterns - Elements of Reusable Object-Oriented Software” Initiated the concept of Design Pattern in Software development These authors are known as Gang of Four (GOF) According to these authors design patterns are based on the following principles of object orientated design: Program to an interface not an implementation Favor object composition over inheritance (Has-A vs Is-A)

7 Usage of Design Patterns

8 Usage of Design Patterns
Design patterns have two main usages in development: Common platform for developers Design patterns provide a standard terminology and are specific to particular scenario For example, a singleton design pattern signifies use of single object so all developers familiar with single design pattern & its usage Best Practices Design patterns have been evolved over a long period of time and they provide best solutions to certain problems faced during software development Learning these patterns helps inexperienced developers to learn software design in an easy and faster way

9 Types of Design Patterns

10 Types of Design Patterns
As per the design pattern reference book, there are 23 design patterns classified in three categories: Creational Patterns These design patterns provide a way to create objects while hiding the creation logic, rather than instantiating objects directly using new operator This gives program more flexibility in deciding which objects need to be created for a given use case Structural Patterns These design patterns concern class and object composition Concept of inheritance is used to compose interfaces and define ways to compose objects to obtain new functionalities

11 Types of Design Patterns
Behavioral Patterns These design patterns are specifically concerned with communication between objects

12 Singleton Pattern

13 Singleton Pattern In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to one object This type of design pattern comes under creational pattern as this pattern provides one of the best ways to create an object Characteristics: A single constructor, which is private and parameter-less which prevents other classes from instantiating it (which would be a violation of the pattern) It prevents subclassing - if a singleton can be subclassed once, it can be subclassed twice, and if each of those subclasses can create an instance, the pattern is violated

14 Singleton Pattern A static variable which holds a reference to the single created instance, if any A public static means of getting the reference to the single created instance, creating one if necessary

15 Singleton Pattern Singleton.cs

16 Singleton Pattern Program.cs

17 Decorator Pattern

18 Decorator Pattern

19 Decorator Pattern

20 Decorator Pattern Decorator pattern allows a user to add new functionality to an existing object without altering its structure This type of design pattern comes under structural pattern as this pattern acts as a wrapper to existing class

21 Decorator Pattern Characteristics: Component (Vehicle)
This is an interface containing members that will be implemented by ConcreteClass and Decorator ConcreteComponent (HondaCity) This is a class which implements the Component interface Decorator (VehicleDecorator) This is an abstract class which implements the Component interface and contains the reference to a Component instance & this class also acts as base class for all decorators ConcreteDecorator (SpecialOffer) This is a class which inherits from Decorator class and provides a decorator for components

22 Decorator Pattern

23 Any ?


Download ppt "Design Patterns Imran Rashid CTO at ManiWeber Technologies."

Similar presentations


Ads by Google