Acceptor-Patterns4.Pdf

Total Page:16

File Type:pdf, Size:1020Kb

Acceptor-Patterns4.Pdf Table of Contents Object-Oriented Network Overview Programming with C++ { Recognizing patterns { Typ es of patterns Design Patterns for Initializing Passively initiali zi ng network services Network Services in OO { Overview of tactical patterns Communication Frameworks { Overview of strategic patterns Implementing the Acceptor pattern Douglas C. Schmidt { First implementation [email protected] u { Revised implementation Washington University Summary 2 1 Identifying Common Behavior and Structure Intro duction \Pattern recognition" o ccurs by observing Design patterns capture successful solutions recurring solution strategies to recurring problems that arise during soft- ware development e.g., network servers often lo ok as follows: Useful design patterns and design pattern void do_server void { descriptions, like useful software, evolve over listener_handle.initialize ; time for ;; { { Likewise, patterns build up on other patterns to // Create service to handle connection. form families of related patterns service = new Service; // Wait for and accept connection. client_handle = listener_handle.accept ; The following material captures the evolu- // Activate service. tion of design patterns that are useful for service->open client_handle; managing the lifecycle of services in OO // Perform service. communication software service->run ; } } 3 4 Identifying Limitations with the Strategic and Tactical Patterns Existing Solution Strategic design patterns have an extensive impact on the software architecture The solution ab ove is limit ed by tightly cou- pling: { Typically oriented to solutions in aparticular do- main { Choice of IPC mechanisms { Connection and service handling strategies { e.g., Reactor and Acceptor pattern in the domain of event-driven, connection-oriented communica- { Choice of demultiplexing strategy tion software { Choice of advertisement strategy { Choice of endp oint listening strategy Tactical design patterns have a relatively lo- calized impact on a software architecture { Choice of service creation strategy { Typically domain-indep endent { Choice of connection acceptance strategy { e.g.,Wrapp er, Adapter, Bridge, Factory Metho d, { Choice of service concurrency strategy and Strategy Strategic and tactical design patterns re- It is imp ortant to understand b oth typ es of move these limitati ons and decrease cou- patterns pling 6 5 Decoupling IPC Mechanisms Problem The Wrapp er Pattern { IPC mechanisms likesockets, TLI, and STREAM pip es have non-uniform interfaces, even though they b ehavior similarly Intent { Encapsulate lower-level functions within typ e-safe, mo dular, and p ortable class interfaces Key forces { Many IPC mechanisms or subsets of mechanisms provide logically equivalent services even though This pattern resolves the following force that their interfaces are physically di erent arises when using native C-level OS APIs . e.g., TLI vs. so ckets 1. How to avoid tedious, error-prone, and non-p ortable programming of low-level IPC mechanisms { Many IPC mechanisms are written in low-level C co de 2. How to combine multiple related, but indep endent, functions into a single cohesive abstraction Solution { Use the Wrapp er and Adapter patterns 7 8 Structure of the Wrapp er Pattern The Adapter Pattern Intent 1: request () Wrapper Convert the interface of a class into another inter- client { request() face client exp ects . Adapter lets classes work together that couldn't otherwise b ecause of incompatible interfaces 2: specific_request() This pattern resolves the following force that rises when using conventional OS inter- Wrappee a faces specific_request() 1. `How to provide an interface that expresses the similarities of seemingly di erent OS mechanisms such as networking or lo cking 9 10 Decoupling Demultip lexi ng Strategy Structure of the Adapter Pattern Problem Servers often must handle events from more than 1: request () { Target one source client request() = 0 A Key forces { It is inecient to rep eatedly \p oll" each event source and it is incorrect to blo ck inde nitely on Adapter Adaptee any one source of events specific_request() request() 2: specific_request() { Extensibility is limited if the demultiplexing co de is coupled with the application event handling co de Solution { Use the Reactor pattern 12 11 Structure The Reactor Pattern select (handles) Concrete foreach h in handles loop APPLICATION Event Intent h->handle_event (type) APPLICATION end loop Handler Decouple event demultiplexing and event handler { - SPECIFIC - rmed in resp onse dispatching from the services p erfo INDEPENDENT to events Reactor handle_events() 1 n register_handler(eh, type) This pattern resolves the following forces r event-driven software: fo remove_handler(eh, type) Event Handler 1 1 handle_event(type) How to demultiplex multiple typ es of events from 1. 1 multiple sources of events eciently within a single get_handle() thread of control n Handles A 2. How to extend application b ehavior without requir- ing changes to the event demultiplexing/dispatching framework Participants in the Reactor pattern 14 13 Collab oratio ns Decoupling Connection and Handling Strategies callback : Service main Concrete reactor program Event_Handler : Reactor Problem Reactor() INITIALIZE register_handler(callback) Coupling initialization strategies with the service REGISTER HANDLER { MODE es it hard to change either one with- get_handle() handling mak EXTRACT HANDLE handle_events() out a ecting the other INITIALIZATION START EVENT LOOP select() FOREACH EVENT DO handle_event() Key forces EVENT OCCURS MODE EVENT Services tend to change more often than connec- REMOVE HANDLER handle_close() { HANDLING tion establishment strategies Solution Dynamic interaction among participants in { Use the Acceptor pattern the Reactor pattern 16 15 The Acceptor Pattern Intent Structure of the Acceptor Pattern { Decouple the passive initialization of a service from the tasks p erformed once the service is initialized Svc Handler This pattern resolves the following forces Svc Handler Acceptor r network servers using interfaces like so ck- fo peer_stream_ or TLI: ets peer_acceptor_ open() ACTIVATES handle_event() 1. How to reuse passive connection establishment co de for each new service Reactor 2. How to make the connection establishment co de rtable across platforms that may contain di er- po handle_event() ent IPC mechanisms 3. How to ensure that a passive-mo de descriptor is not accidentally used to read or write data 4. How to enable exible strategies for creation, con- nection establishment, and concurrency 18 17 Structure of the First Acceptor Pattern Implementati on First Implementati on of the Concrete_Svc_Handler SOCK Stream n SOCK_Acceptor r Pattern Accepto 1 Concrete Concrete Svc Handler Acceptor LAYER LAYER The following slides illustrate an implemen- ACTIVATES APPLICATION APPLICATION tation of the Acceptor pattern { This solution relies up on an implementation of the PEER_STREAM r pattern, as well as the Adapter pattern Reacto Svc SVC_HANDLER A PEER_ACCEPTOR Handler Acceptor A open() handle_event() Subsequent slides will describ e limitati ons LAYER LAYER CONNECTION CONNECTION with this rst approach sh = new SVC_HANDLER; peer_acceptor.accept(*sh); reactor->register_handler (sh); Other tactical patterns will be used to re- Event these limitati ons move Handler 1 Reactor LAYER LAYER handle_event() n REACTIVE REACTIVE 19 20 Typical Acceptor Use-Case Acceptor Class Interface SERVER A factory for initial i zi ng network services LOGGING : Logging passively DAEMON Acceptor <class SVC_HANDLER, // Type of service template : Logging PEER_ACCEPTOR> // Accepts connections class Handler class Acceptor : public Event_Handler { public: : Logging Initialize and register with Reactor. // Handler : Reactor virtual int open const PEER_ACCEPTOR::PEER_ADDR &, Reactor *; // Creates, accepts, and activates SVC_HANDLER's. LOGGING virtual int handle_event HANDLE; RECORDS Demultiplexing hooks. // LOGGING CONNECTION SERVER HANDLE get_handle void const; virtual RECORDS REQUEST CLIENT private: // Passive connection mechanism. EPTOR peer_acceptor_; PEER_ACC CLIENT CLIENT // Event demultiplexor. Reactor *reactor_; }; 22 21 Acceptor Use-case Co de Distributed logging server Acceptor Class Implementation // Shorthand names. class Logging_Handler : define SH SVC_HANDLER public Svc_Handler<SOCK_Stream> define PR_AC PEER_ACCEPTOR { public: // Initialize the Acceptor // Obtain HANDLE. virtual HANDLE get_handle void const; template <class SH, class PR_AC> int Acceptor<SH, PR_AC>::open const PR_AC::ADDR &l_addr, // Called back to process logging records. Reactor *reactor virtual int handle_event HANDLE; { }; this->reactor_ = reactor; typedef Acceptor<Logging_Handler, SOCK_Acceptor> // Forward to PEER_ACCEPTOR to advertise endpoint. Logging_Acceptor; this->peer_acceptor_.open l_addr; int main void { // Register with Reactor to listen for connections. Reactor reactor; Logging_Acceptor acceptor; this->reactor_->register_handler this, READ_MASK; acceptor.open LOGGER_PORT, &reactor; } for ;; reactor.handle_events ; } 23 24 Collab orati on in the Acceptor Pattern acc : Server sh: reactor : Acceptor Svc_Handler Reactor Factory that create, connects, and activates new // open() INITIALIZE single-threaded SVC_HANDLER objects. // register_handler(acc) REGISTER HANDLER get_handle() <class SH, class PR_AC> int template EXTRACT HANDLE <SH, PR_AC>::handle_event HANDLE Acceptor handle_events() PHASE START EVENT LOOP ENDPOINT { FOREACH
Recommended publications
  • Automatic Verification of Java Design Patterns
    Automatic Verification of Java Design Patterns Alex Blewitt, Alan Bundy, Ian Stark Division of Informatics, University of Edinburgh 80 South Bridge, Edinburgh EH1 1HN, UK [email protected] [email protected] [email protected] Abstract 2. Design patterns There are a number of books which catalogue and de- Design patterns are widely used by object oriented de- scribe design patterns [4, 1, 6] including an informal de- signers and developers for building complex systems in ob- scription of the key features and examples of their use. ject oriented programming languages such as Java. How- However, at the moment there are no books which attempt ever, systems evolve over time, increasing the chance that to formalise these descriptions, possibly for the following the pattern in its original form will be broken. reasons: We attempt to show that many patterns (implemented in Java) can be verified automatically. Patterns are defined 1. The implementation (and description) of the pattern is in terms of variants, mini-patterns, and constraints in a language-specific. pattern description language called SPINE. These specifi- 2. There are often several ways to implement a pattern cations are then processed by HEDGEHOG, an automated within the same language. proof tool that attempts to prove that Java source code 3. Formal language descriptions are not common within meets these specifications. the object oriented development community. Instead, each pattern is presented as a brief description, and an example of its implementation and use. Designers and developers are then expected to learn the ‘feel’ of a pat- 1.
    [Show full text]
  • Addison Wesley, 2000, Pp
    ------==Proudly Presented by MODELER==------ preface.fm Page xv Wednesday, June 6, 2001 4:18 PM Preface Design patterns and object-oriented programming. They hold such promise to make your life as a software designer and developer eas- ier. Their terminology is bandied about every day in the technical and even the popular press. But it can be hard to learn them, to become proficient with them, to understand what is really going on. Perhaps you have been using an object-oriented or object-based language for years. Have you learned that the true power of objects is not inheritance but is in “encapsulating behaviors”? Perhaps you are curious about design patterns and have found the literature a bit too esoteric and high-falutin. If so, this book is for you. It is based on years of teaching this material to software developers, both experienced and new to object orientation. It is based upon the belief—and our experience—that once you understand the basic principles and motivations that underlie these concepts, why they are doing what they do, your learning curve will be incredibly shorter. And in our discussion of design patterns, you will under- stand the true mindset of object orientation, which is a necessity before you can become proficient. As you read this book, you will gain a solid understanding of the ten most essential design patterns. You will learn that design pat- terns do not exist on their own, but are supposed to work in con- cert with other design patterns to help you create more robust applications.
    [Show full text]
  • Object-Oriented Analysis, Design and Implementation
    Undergraduate Topics in Computer Science Brahma Dathan Sarnath Ramnath Object-Oriented Analysis, Design and Implementation An Integrated Approach Second Edition Undergraduate Topics in Computer Science Undergraduate Topics in Computer Science (UTiCS) delivers high-quality instruc- tional content for undergraduates studying in all areas of computing and information science. From core foundational and theoretical material to final-year topics and applications, UTiCS books take a fresh, concise, and modern approach and are ideal for self-study or for a one- or two-semester course. The texts are all authored by established experts in their fields, reviewed by an international advisory board, and contain numerous examples and problems. Many include fully worked solutions. More information about this series at http://www.springer.com/series/7592 Brahma Dathan • Sarnath Ramnath Object-Oriented Analysis, Design and Implementation An Integrated Approach Second Edition 123 Brahma Dathan Sarnath Ramnath Department of Information and Computer Department of Computer Science Science and Information Technology Metropolitan State University St. Cloud State University St. Paul, MN St. Cloud, MN USA USA Series editor Ian Mackie Advisory Board Samson Abramsky, University of Oxford, Oxford, UK Karin Breitman, Pontifical Catholic University of Rio de Janeiro, Rio de Janeiro, Brazil Chris Hankin, Imperial College London, London, UK Dexter Kozen, Cornell University, Ithaca, USA Andrew Pitts, University of Cambridge, Cambridge, UK Hanne Riis Nielson, Technical University of Denmark, Kongens Lyngby, Denmark Steven Skiena, Stony Brook University, Stony Brook, USA Iain Stewart, University of Durham, Durham, UK A co-publication with the Universities Press (India) Private Ltd., licensed for sale in all countries outside of India, Pakistan, Bhutan, Bangladesh, Sri Lanka, Nepal, The Maldives, Middle East, Malaysia, Indonesia and Singapore.
    [Show full text]
  • A Mathematical Approach to Object Oriented Design Patterns
    06.2006 J.Natn.Sci.FoundationObject oriented design Sripatterns Lanka 2008 36 (3):219-227 219 RESEARCH ARTICLE A mathematical approach to object oriented design patterns Saluka R. Kodituwakku1*and Peter Bertok2 1 Department of Statistics and Computer Science, Faculty of Science, University of Peradeniya, Peradeniya. 2 Department of Computer Science, RMIT University, Melbourne, Australia. Revised: 27 May 2008 ; Accepted: 18 July 2008 Abstract: Although design patterns are reusable design the distribution of responsibilities. For ease of learning elements, existing pattern descriptions focus on specific and reference, in1, design patterns are organized into a solutions that are not easily reusable in new designs. This paper catalogue. introduces a new pattern description method for object oriented design patterns. The description method aims at providing a The catalogue is formed by two criteria: purpose more general description of patterns so that patterns can be and scope. According to their purpose, design patterns readily reusable. This method also helps a programmer to are classified into creational, structural and behavioural, analyze, compare patterns, and detect patterns from existing software programmes. whereas the scope divides patterns into class patterns and object patterns. Class patterns capture relationships This method differs from the existing pattern description between classes and their subclasses; object patterns deal methods in that it captures both static and dynamic properties with relationships between objects. of patterns. It describes them in terms of mathematical entities rather than natural language narratives, incomplete graphical Software patterns provide reusable solutions to notations or programme fragments. It also helps users to recurring design problems. Even if we have reusable understand the patterns and relationships between them; and solutions they may not be effectively reused, because select appropriate patterns to the problem at hand.
    [Show full text]
  • The Scalable Adapter Design Pattern: Enabling Interoperability Between Educational Software Tools
    The Scalable Adapter Design Pattern: Enabling Interoperability Between Educational Software Tools Andreas Harrer, Catholic University Eichstatt-Ingolstadt,¨ Germany, Niels Pinkwart, Clausthal University of Technology, Germany, Bruce M. McLaren, Carnegie Mellon University, Pittsburgh PA, U.S.A., and DFKI, Saarbrucken,¨ Germany, and Oliver Scheuer, DFKI, Saarbrucken,¨ Germany Abstract For many practical learning scenarios, the integrated use of more than one learning tool is educationally beneficial. In these cases, interoperability between learning tools - getting the pieces to talk to one another in a coherent, well-founded manner - is a crucial requirement that is often hard to achieve. This paper describes a re-usable software design that aims at the integration of independent learning tools into one collaborative learning scenario. We motivate the usefulness and expressiveness of combining several learning tools into one integrated learning experience. Based on this we sketch software design principles that integrate several existing components into a joint technical framework. The feasibility of the approach, which we name the “Scalable Adapter” design pattern, is shown with several implementation examples from different educational technology domains, including Intelligent Tutoring Systems and collaborative learning environments. IEEE keywords: J.m Computer applications, H.5.3 Group and Organization interfaces, K.3.m Computers in Education A short version of this paper appeared in the Proceedings of the Conference on Intelligent Tutoring Systems 2008 1 The Scalable Adapter Design Pattern: Enabling Interoperability Between Educational Software Tools1 I. INTRODUCTION hypothesis and plans. In order to help the student or student In the field of educational technology, there have been groups during the different steps of this inquiry procedure, it numerous attempts in recent years to connect differently makes sense to enable them to have hypotheses, experimenta- targeted learning environments to one another.
    [Show full text]
  • Design Patterns in Ocaml
    Design Patterns in OCaml Antonio Vicente [email protected] Earl Wagner [email protected] Abstract The GOF Design Patterns book is an important piece of any professional programmer's library. These patterns are generally considered to be an indication of good design and development practices. By giving an implementation of these patterns in OCaml we expected to better understand the importance of OCaml's advanced language features and provide other developers with an implementation of these familiar concepts in order to reduce the effort required to learn this language. As in the case of Smalltalk and Scheme+GLOS, OCaml's higher order features allows for simple elegant implementation of some of the patterns while others were much harder due to the OCaml's restrictive type system. 1 Contents 1 Background and Motivation 3 2 Results and Evaluation 3 3 Lessons Learned and Conclusions 4 4 Creational Patterns 5 4.1 Abstract Factory . 5 4.2 Builder . 6 4.3 Factory Method . 6 4.4 Prototype . 7 4.5 Singleton . 8 5 Structural Patterns 8 5.1 Adapter . 8 5.2 Bridge . 8 5.3 Composite . 8 5.4 Decorator . 9 5.5 Facade . 10 5.6 Flyweight . 10 5.7 Proxy . 10 6 Behavior Patterns 11 6.1 Chain of Responsibility . 11 6.2 Command . 12 6.3 Interpreter . 13 6.4 Iterator . 13 6.5 Mediator . 13 6.6 Memento . 13 6.7 Observer . 13 6.8 State . 14 6.9 Strategy . 15 6.10 Template Method . 15 6.11 Visitor . 15 7 References 18 2 1 Background and Motivation Throughout this course we have seen many examples of methodologies and tools that can be used to reduce the burden of working in a software project.
    [Show full text]
  • A Design Pattern Generation Tool
    Project Number: GFP 0801 A DESIGN PATTERN GEN ERATION TOOL A MAJOR QUALIFYING P ROJECT REPORT SUBMITTED TO THE FAC ULTY OF WORCESTER POLYTECHNIC INSTITUTE IN PARTIAL FULFILLME NT OF THE REQUIREMEN TS FOR THE DEGREE OF BACHELOR O F SCIENCE BY CAITLIN VANDYKE APRIL 23, 2009 APPROVED: PROFESSOR GARY POLLICE, ADVISOR 1 ABSTRACT This project determines the feasibility of a tool that, given code, can convert it into equivalent code (e.g. code that performs the same task) in the form of a specified design pattern. The goal is to produce an Eclipse plugin that performs this task with minimal input, such as special tags.. The final edition of this plugin will be released to the Eclipse community. ACKNOWLEGEMENTS This project was completed by Caitlin Vandyke with gratitude to Gary Pollice for his advice and assistance, as well as reference materials and troubleshooting. 2 TABLE OF CONTENTS Abstract ....................................................................................................................................................................................... 2 Acknowlegements ................................................................................................................................................................... 2 Table of Contents ..................................................................................................................................................................... 3 Table of Illustrations .............................................................................................................................................................
    [Show full text]
  • Additional Design Pattern Examples Design Patterns--Factory Method
    Additional Design Pattern Examples • Creational – Factory method – Abstract factory • Structural – Decorator – Adapter • Behavioral – Observer Design Patterns--Factory Method • Intent--Permit a class to be reuseable with arbitrary data types. Specifically, allow the class to be independent of the classes it instantiates – Define an interface for object creation. – Let subclasses decide which class to instantiate. • Motivation – Useful for development of frameworks 1 Factory Method--Continued • Consider a document-processing framework – High-level support for creating, opening, saving documents – Consistent method calls for these commands, regardless of document type (word-processor, spreadsheet, etc.) – Logic to implement these commands delegated to specific types of document objects. – May be some operations common to all document types. Factory Method--Continued Document Processing Example-General Framework: Document Application getTitle( ) * Edits 1 newDocument( ) newDocument( ) openDocument( ) openDocument( ) ... ... MyDocument Problem: How can an Application object newDocument( ) create instances of specific document classes openDocument( ) without being application-specific itself. ... 2 Factory Method--Continued Use of a document creation “factory”: Document Application getTitle( ) * Edits 1 newDocument( ) newDocument( ) openDocument( ) openDocument( ) ... ... 1 requestor * Requests-creation creator 1 <<interface>> MyDocument DocumentFactoryIF newDocument( ) createDocument(type:String):Document openDocument( ) ... DocumentFactory
    [Show full text]
  • Design Patterns Adapter Pattern
    DDEESSIIGGNN PPAATTTTEERRNNSS -- AADDAAPPTTEERR PPAATTTTEERRNN http://www.tutorialspoint.com/design_pattern/adapter_pattern.htm Copyright © tutorialspoint.com Adapter pattern works as a bridge between two incompatible interfaces. This type of design pattern comes under structural pattern as this pattern combines the capability of two independent interfaces. This pattern involves a single class which is responsible to join functionalities of independent or incompatible interfaces. A real life example could be a case of card reader which acts as an adapter between memory card and a laptop. You plugin the memory card into card reader and card reader into the laptop so that memory card can be read via laptop. We are demonstrating use of Adapter pattern via following example in which an audio player device can play mp3 files only and wants to use an advanced audio player capable of playing vlc and mp4 files. Implementation We have a MediaPlayer interface and a concrete class AudioPlayer implementing the MediaPlayer interface. AudioPlayer can play mp3 format audio files by default. We are having another interface AdvancedMediaPlayer and concrete classes implementing the AdvancedMediaPlayer interface. These classes can play vlc and mp4 format files. We want to make AudioPlayer to play other formats as well. To attain this, we have created an adapter class MediaAdapter which implements the MediaPlayer interface and uses AdvancedMediaPlayer objects to play the required format. AudioPlayer uses the adapter class MediaAdapter passing it the desired audio type without knowing the actual class which can play the desired format. AdapterPatternDemo, our demo class will use AudioPlayer class to play various formats. Step 1 Create interfaces for Media Player and Advanced Media Player.
    [Show full text]
  • Java Design Patterns I
    Java Design Patterns i Java Design Patterns Java Design Patterns ii Contents 1 Introduction to Design Patterns 1 1.1 Introduction......................................................1 1.2 What are Design Patterns...............................................1 1.3 Why use them.....................................................2 1.4 How to select and use one...............................................2 1.5 Categorization of patterns...............................................3 1.5.1 Creational patterns..............................................3 1.5.2 Structural patterns..............................................3 1.5.3 Behavior patterns...............................................3 2 Adapter Design Pattern 5 2.1 Adapter Pattern....................................................5 2.2 An Adapter to rescue.................................................6 2.3 Solution to the problem................................................7 2.4 Class Adapter..................................................... 11 2.5 When to use Adapter Pattern............................................. 12 2.6 Download the Source Code.............................................. 12 3 Facade Design Pattern 13 3.1 Introduction...................................................... 13 3.2 What is the Facade Pattern.............................................. 13 3.3 Solution to the problem................................................ 14 3.4 Use of the Facade Pattern............................................... 16 3.5 Download the Source Code.............................................
    [Show full text]
  • Gof Design Patterns
    GoF Design Patterns CSC 440: Software Engineering Slide #1 Topics 1. GoF Design Patterns 2. Template Method 3. Strategy 4. Composite 5. Adapter CSC 440: Software Engineering Slide #2 Design Patterns Book Classic text that started Design Patterns movement written by the Gang of Four (GoF). We’ll introduce several widely used patterns from the book. Useful solutions for certain problems, but if you don’t have the problem, don’t use the pattern. CSC 440: Software Engineering Slide #3 GoF Design Patterns Catalog Behavioral Creational Structural Interpreter Factory Adapter Template Abstract Factory Bridge method Builder Chain of Composite Responsibility Prototype Decorator Command Singleton Façade Iterator Flyweight Mediator Memento Proxy Observer State Strategy Visitor CSC 440: Software Engineering Slide #4 GoF and GRASP Patterns GoF patterns are specializations and/or combinations of the more fundamental GRASP design patterns. Example: Adapter Pattern provides Protected Variations through use of Indirection and Polymorphism CSC 440: Software Engineering Slide #5 Template Method Pattern Name: Template Method Problem: How to implement an algorithm that varies in certain circumstances? Solution: Define the skeleton of the algorithm in the superclass, deferring implementation of the individual steps to the subclasses. CSC 440: Software Engineering Slide #6 Example: The Report Class class Report def output_report(format) if format == :plain puts(“*** #{@title} ***”) elsif format == :html puts(“<html><head>”) puts(“<title>#{@title}</title>”)
    [Show full text]
  • Object-Oriented Design Patterns
    Object-Oriented Design Patterns David Janzen EECS 816 Object-Oriented Software Development University of Kansas Outline • Introduction – Design Patterns Overview – Strategy as an Early Example – Motivation for Creating and Using Design Patterns – History of Design Patterns • Gang of Four (GoF) Patterns – Creational Patterns – Structural Patterns – Behavioral Patterns Copyright © 2006 by David S. 2 Janzen. All rights reserved. What are Design Patterns? • In its simplest form, a pattern is a solution to a recurring problem in a given context • Patterns are not created, but discovered or identified • Some patterns will be familiar? – If you’ve been designing and programming for long, you’ve probably seen some of the patterns we will discuss – If you use Java Foundation Classes (Swing), Copyright © 2006 by David S. 3 you have certaJiannzleyn. Aulls rieghdts rsesoervmed.e design patterns Design Patterns Definition1 • Each pattern is a three-part rule, which expresses a relation between – a certain context, – a certain system of forces which occurs repeatedly in that context, and – a certain software configuration which allows these forces to resolve themselves 1. Dick Gabriel, http://hillside.net/patterns/definition.html Copyright © 2006 by David S. 4 Janzen. All rights reserved. A Good Pattern1 • Solves a problem: – Patterns capture solutions, not just abstract principles or strategies. • Is a proven concept: – Patterns capture solutions with a track record, not theories or speculation 1. James O. Coplien, http://hillside.net/patterns/definition.html Copyright © 2006 by David S. 5 Janzen. All rights reserved. A Good Pattern • The solution isn't obvious: – Many problem-solving techniques (such as software design paradigms or methods) try to derive solutions from first principles.
    [Show full text]