A Brief Introduction to Design Patterns

A Brief Introduction to Design Patterns A Brief Introduction to Design Patterns - Start

Added : 2016-03-25 Views :61K

Download Presentation

A Brief Introduction to Design Patterns




Download Presentation - The PPT/PDF document "A Brief Introduction to Design Patterns" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.



Presentations text content in A Brief Introduction to Design Patterns

Slide1

A Brief Introduction to Design Patterns

Based on materials from Doug Schmidt

1

Slide2

Object-oriented design

OOD methods emphasize design notationsFine for specification, documentationBut OOD is more than just drawing diagramsGood draftsmen, good designersGood OO designers rely on lots of experienceAt least as important as syntaxMost powerful reuse is design reuseMatch problem to design experienceOO systems exhibit recurring structures that promote: abstraction, flexibility, modularity, elegance

2

Slide3

A design pattern

Abstracts a recurring design structureComprises class and/or objectdependenciesstructuresinteractionsconventionsNames and specifies the design structure explicitlyDistills design experience

3

Slide4

Four basic parts

NameProblemSolutionTrade-offs of application

4

Slide5

Example: Observer pattern

5

Slide6

Observer pattern components [1/2]

6

Slide7

Observer pattern components [2/2]

7

Slide8

Design patterns goals

Codify good designdistill & generalize experienceaid to novices & experts alikeGive design structures explicit namescommon vocabularyreduced complexitygreater expressivenessCapture & preserve design informationarticulate design decisions succinctlyimprove documentationFacilitate restructuring/refactoringpatterns are interrelatedadditional flexibility

8

Slide9

GoF design patterns

Scope

: domain over which a pattern appliesPurpose: reflects what a pattern does

9

GoF:  Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides

Slide10

Design pattern template [1/2]

Intentshort description of the pattern & its purposeAlso Known AsAny aliases this pattern is known byMotivationmotivating scenario demonstrating pattern’s useApplicabilitycircumstances in which pattern appliesStructuregraphical representation of the pattern using modified UML notationParticipantsparticipating classes and/or objects & their responsibilities

10

Slide11

Design pattern template [2/2]

Collaborationshow participants cooperate to carry out their responsibilitiesConsequencesthe results of application, benefits, liabilitiesImplementationpitfalls, hints, techniques, plus language-dependent issuesSample Codesample implementations in C++, Java, C#, Smalltalk, C, etc.Known Usesexamples drawn from existing systemsRelated Patternsdiscussion of other patterns that relate to this one

11

Slide12

UML/OMT notation

12

Slide13

13

Observer design pattern [1/3]

Intentdefine a one-to-many dependency between objects so that when one object changes state, all dependents are notified & updatedApplicabilityan abstraction has two aspects, one dependent on the othera change to one object requires changing untold othersan object should notify unknown other objectsStructure

Slide14

14

Observer design pattern [2/3]

class ProxyPushConsumer : public // … virtual void push (const CORBA::Any &event) { for (std::vector<PushConsumer>::iterator i (consumers.begin ()); i != consumers.end (); i++) (*i).push (event); }

class MyPushConsumer : public // ….

virtual void push

(const CORBA::Any &event) { /* consume the event. */ }

Slide15

15

Observer design pattern

[3/3]

Consequences

modularity: subject & observers may vary independently

extensibility: can define & add any number of observers

customizability: different observers offer different views of subject

unexpected updates: observers don’t know about each other

update overhead: might need hints or filtering

Implementation

subject-observer mapping

dangling references

update protocols: the push & pull models

registering modifications of interest explicitly

Known Uses

Smalltalk Model-View-Controller (MVC)

InterViews

(Subjects & Views, Observer/Observable)

Andrew (Data Objects & Views)

Pub/sub middleware (e.g., CORBA Notification Service, Java Messaging Service)

Mailing lists

Slide16

Benefits of design patterns

Design reuseUniform design vocabularyEnhance understanding, restructuring, & team communicationBasis for automationTranscends language-centric biases/myopiaAbstracts away from many unimportant details

16

Slide17

Another example pattern: Template

Provides a skeleton of an algorithm in a method, deferring some steps to subclasses

class Base_Class {public: // Template Method. void template_method (void) { hook_method_1 (); hook_method_2 (); // ... } virtual void hook_method_1 () = 0; virtual void hook_method_2 () = 0;}; class Derived_Class_1 : public Base_Class { virtual void hook_method_2 () { /* ... */ }};class Derived_Class_2 : public Base_Class { virtual void hook_method_1 () { /* ... */ } virtual void hook_method_2 () { /* ... */ }};

17

Slide18

Yet another design pattern: adapter

When two software components (e.g., legacy code and new development or a COTS) cannot interfaceAdapter changes interface of one so the other can use itAdapter fills the gap b/w two interfacesNo changes needed for either

18

Slide19

Yet another design pattern:

adapter [2/2]

class

NewTime {public:int GetTime() { return otime.get_time() * 100; }private: OriginalTime otime;};

19

An alternate: a

wrapper

Slide20

Relationship with other design concepts

20

Slide21

Slide22

Slide23

Slide24

Slide25

Slide26


About DocSlides
DocSlides allows users to easily upload and share presentations, PDF documents, and images.Share your documents with the world , watch,share and upload any time you want. How can you benefit from using DocSlides? DocSlides consists documents from individuals and organizations on topics ranging from technology and business to travel, health, and education. Find and search for what interests you, and learn from people and more. You can also download DocSlides to read or reference later.
Youtube