Milad Abolhassani tuxgeek.ir milad@tuxgeek.ir Slides: - - PowerPoint PPT Presentation

milad abolhassani
SMART_READER_LITE
LIVE PREVIEW

Milad Abolhassani tuxgeek.ir milad@tuxgeek.ir Slides: - - PowerPoint PPT Presentation

Design Pattern Milad Abolhassani tuxgeek.ir milad@tuxgeek.ir Slides: http://slideshare.com/miladas http://miladas.github.io/slides Attention 2 OOP 3 Class Interface Property Abstract class Method Encapsulation


slide-1
SLIDE 1

Design Pattern

Milad Abolhassani

tuxgeek.ir milad@tuxgeek.ir

Slides:

http://slideshare.com/miladas http://miladas.github.io/slides

slide-2
SLIDE 2

Attention

2

slide-3
SLIDE 3

OOP

  • Class
  • Property
  • Method
  • Inheritance
  • Polymorphism
  • Interface
  • Abstract class
  • Encapsulation
  • Public/protected/private
  • Final

3

slide-4
SLIDE 4

Where did all of these come from?

4

slide-5
SLIDE 5

SOLID

SOLID

5

slide-6
SLIDE 6

SOLID

  • Single Responsibility
  • Open/Closed
  • Liskov substitution
  • Interface Segregation
  • Dependency Injection

6

slide-7
SLIDE 7

Single Responsibility

7

slide-8
SLIDE 8

Open/Closed

  • Meyer’s open/closed

Once class completed, never should modified

  • Polymorphic open/closed principle

Interface (public methods)

The interface is open for extension but close for modification 8

slide-9
SLIDE 9

Liskov substitution

  • Program to an interface rather than of it’s implementation
  • Design by contract
  • Do not extend the interface

9

slide-10
SLIDE 10

Interface Segregation

10

slide-11
SLIDE 11

Dependency injection

11

slide-12
SLIDE 12

What is design pattern?

  • In software engineering, a design pattern is a general reusable

solution to a commonly occurring problem.

12

slide-13
SLIDE 13

History

  • Patterns originated as an architectural concept by Christopher

Alexander (1977/79).

  • Design patterns gained popularity in computer science after the book

Design Patterns: Elements of Reusable Object-Oriented Software was published in 1994.

– Gang of Four – Gamma, Erich; Helm, Richard; Johnson, Ralph; Vlissides, John 13

slide-14
SLIDE 14

Gang of four

14

slide-15
SLIDE 15

Why design pattern?

  • Clarity
  • Correctness
  • Same vocabularies

– Avoid miss communications

  • Reuse
  • Save time, trial and error
  • Can speed up the development process

– by providing tested, proven development paradigms

  • We are not reusing code, we are reusing experience

15

slide-16
SLIDE 16

Category

  • Creational design patterns
  • Structural design patterns
  • Behavioral design patterns

16

slide-17
SLIDE 17

Creational design patterns

  • These design patterns provide a way to create objects while hiding the

creation logic.

17

slide-18
SLIDE 18

Creational design patterns

  • Factory method
  • Singleton
  • Prototype
  • Builder

18

slide-19
SLIDE 19

Factory Method

19

  • Factory Method lets a class defer instantiation to

subclasses.

slide-20
SLIDE 20

Singleton

  • This pattern involves a single class which is responsible to create an
  • bject while making sure that only single object gets created.

20

slide-21
SLIDE 21

Prototype

  • Specify the kinds of objects to create using a prototypical instance, and

create new objects by copying this prototype.

21

slide-22
SLIDE 22

Builder

  • Separate the construction of a complex object from its representation

so that the same construction process can create difgerent representations.

22

slide-23
SLIDE 23

Programmer

23

slide-24
SLIDE 24

Structural design patterns

  • These design patterns are all about Class and Object composition.

Concept of inheritance is used to compose interfaces and defjne ways to compose objects to obtain new functionalities.

24

slide-25
SLIDE 25

Structural design patterns

  • Adapter
  • Decorator
  • Facade
  • Flyweight
  • Proxy

25

slide-26
SLIDE 26

Adapter

  • Convert the interface of a class into another interface clients expect.

Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

26

slide-27
SLIDE 27

Decorator

  • Attach additional responsibilities to an object dynamically.

27

slide-28
SLIDE 28

Decorator

28

slide-29
SLIDE 29

Facade

  • Wrap a complicated subsystem with a simpler interface.

29

slide-30
SLIDE 30

Flyweight

  • The Flyweight uses sharing to support large numbers of objects

effjciently.

30

slide-31
SLIDE 31

Proxy

  • Use an extra level of indirection to support distributed, controlled, or

intelligent access.

31

slide-32
SLIDE 32

Behavioral design patterns

  • These design patterns are all about Class's objects communication.

Behavioral patterns are those patterns that are most specifjcally concerned with communication between objects.

32

slide-33
SLIDE 33

Behavioral design patterns

  • Chain of responsibility
  • Mediator
  • Observer
  • State
  • Strategy
  • Template method

33

slide-34
SLIDE 34

Chain of responsibility

  • The Chain of Responsibility pattern avoids coupling the sender of a

request to the receiver by giving more than one object a chance to handle the request.

34

slide-35
SLIDE 35
  • The Mediator defjnes an object that controls how a set of objects
  • interact. Loose coupling between colleague objects is achieved by

having colleagues communicate with the Mediator, rather than with each other.

Mediator

35

slide-36
SLIDE 36

Observer

  • Observer pattern is used when there is one-to-many relationship

between objects such as if one object is modifjed, its depenedent

  • bjects are to be notifjed automatically.

36

slide-37
SLIDE 37

State

  • The State pattern allows an object to change its behavior when its

internal state changes.

37

slide-38
SLIDE 38

Strategy

  • In Strategy pattern, a class behavior or its algorithm can be changed at

run time.

38

slide-39
SLIDE 39

Template method

  • The Template Method defjnes a skeleton of an algorithm in an
  • peration, and defers some steps to subclasses.

39

slide-40
SLIDE 40

Thank you

slide-41
SLIDE 41

References

– JavaWorld – SourceMaking – TutorialsPoint – Informit – geekswitblogs – Wikipedia [1] [2]