A Metric for Measuring the Abstraction Level of Design Patterns

Total Page:16

File Type:pdf, Size:1020Kb

A Metric for Measuring the Abstraction Level of Design Patterns A Metric for Measuring the Abstraction Level of Design Patterns Atsuto Kubo Hironori Washizaki Yoshiaki Fukazawa Waseda University Waseda University Waseda University Japan Japan Japan [email protected]. [email protected] [email protected] waseda.ac.jp ABSTRACT abstraction level, and is independent from details in design The abstraction level of the problem treated by a design and implementation. Near the end of development, the com- pattern has wide variety, from architecture to near imple- ponents have lower abstraction level, and depend on a con- mentation. There is no objective metric indicating the ab- crete language and environment. There are software pat- straction level of the problems addressed by patterns. Thus, terns addressing problems for each phase. The pattern to it is di±cult to understand the abstraction level of each pat- use for development must have an abstraction level matches tern and to position a new pattern. In this paper, a metric the appropriate level in system development. is proposed. It indicates the relative abstraction level of Developers should select patterns according to the devel- a pattern's problem. We propose a metric obtained from opment phase because a pattern that doesn't matched the inter-pattern relationships. We also propose a visualization system's abstraction level is not e®ective. Therefore, devel- method for the metric. Using such metrics, we aim to help opers need to know the abstraction levels of patterns. In the developers easily understand the abstraction level of each basic design phase, developers should not be aware of idioms, pattern and, therefore, to better decide about its usefulness and in the implementation phase, developers should not be for the problem at hand. aware of architectural patterns. The patterns mismatching current development phase may make developers confused. However, abstraction levels of patterns are di®erent even if Categories and Subject Descriptors they belong to the same pattern catalog. Developers can- D.2.11 [Software Engineering]: Software Architectures| not clearly classify some patterns into architectural patterns, Patterns design patterns, or idioms. For example, let's consider Gang of Four (GoF)'s object- General Terms oriented design patterns [3] and PoSA's patterns [1]. The GoF's design patterns deal with the problems at the granu- Design larity of class design, and PoSA's patterns deal problem at the granularity of system architecture design. However, for Keywords example, GoF's Interpreter pattern is near an architec- Patterns, Interpattern Relationships tural pattern because it uses many other patterns directly and/or indirectly in its solution. It can be thought that the Model-View-Controller (MVC) pattern [4] [1] is near a de- 1. INTRODUCTION sign pattern because it treats individual applications. As A software pattern is a proven solution to a recurring in the above situations, it can be di±cult for developers to problem that appears in the context of software development select patterns ¯tting into considering level of abstraction. [1]. Describing the knowledge of experienced developers pro- If there is a metric that position the Interpreter pattern motes sharing and reusing their knowledge. Many authors near architectural patterns, developers can discuss whether have published many patterns, and most of the patterns to use it or not. However, actually, there is no objective have relationships to other patterns. A pattern collection is metric capable to indicate that. a set of patterns that may or may not be related to each In this paper, we propose a metric that indicates the rel- other. ative abstraction level of each pattern in a set of patterns. In the design phase, developers break the system down The proposed metric is based on the partially-ordered rela- gradually into components. Initially, the system has a higher tionships between two patterns, and aims to assist in: under- standing of the pattern's abstraction level, classifying pat- Preliminary versions of these papers were workshopped at Pattern Lan• terns, and selecting patterns to solve faced problems. guages of Programming (PLoP)’07 September 5•8, 2007, Monticello, IL, USA. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are 2. A METRIC MEASURING THE ABSTRAC• not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to TION LEVEL OF DESIGN PATTERNS republish, to post on servers or to redistribute to lists, requires prior specific There is a wide variation in software design abstraction permission. Copyright is held by the authors. ISBN: 978•1•60558•411•9. PLoP ’07, September 5•8, 2007, Monticello, IL, USA level from architecture to detailed design to implementation. Copyright 2008 is held by the author(s). ACM 978•1•60558•411•9. Developers focus on dividing a system into subsystems at Table 1: A list of inter-pattern relationships Kind of relationship Description Partially-ordered Similar to [8, 6] Pattern X is similar to Pattern Y. No Uses[8, 6, 7] Pattern X uses another pattern Y in its Yes solution. Re¯nes [1, 6], Speci¯c [7] Pattern Y provides a more speci¯c solu- Yes tion than pattern X. Combinable [1] Pattern X and Pattern Y can be com- No bined. Variation [1] Pattern Y is pattern X with some No changes to Y's solution. Provides context [7] Pattern X and Pattern Y can be applied Yes sequentially. ¯rst. Next, they focus on the design of each subsystem, from other patterns. The metric score of a pattern is a dif- modules, and implementation. There can be software pat- ference between the reference count and the backward refer- terns in each abstraction level of software design. ence count of the pattern. In the example shown in Figure 1, Most patterns have one or more inter-pattern relation- the metric score of MVC pattern is six, and of the Composite ships. Authors of patterns often describe these relationships pattern is one. Therefore, developers can see that the MVC in the Related Patterns sections. Table 1 lists some examples pattern is more suitable for architectural design. of inter-pattern relationships. The Partially-ordered column shows whether each relationship is partially-ordered or not. 2.2 Formal definition of the proposed metric For example, the structure of the Interpreter pattern's The reference count of a pattern is the total number of syntax tree can be designed using the Composite pattern. patterns that the pattern can reference transitively on the That is a Uses relationship. Some inter-pattern relation- graph. The graph is composed of patterns (vertices) and ships exist across di®erent pattern catalogs. As another ex- inter-pattern relationships (edges). The backward reference ample, the MVC pattern uses the Observer pattern. count of a pattern is the total number of patterns that ref- In this metric, we use only Uses, Re¯nes, and Provides erences the pattern transitively on the graph. context relationships, i.e., the partially-ordered relationships P is the set of N patterns for which we want to calculate shown on Table 1. The proposed metric has two principles the metric score. below: P = fp1; p2; : : : png; n 2 N: ² Patterns that use other patterns, patterns which are more generalized, and patterns that are applied before The partially-ordered relationship between a pattern p1 and 2 h i other patterns have higher abstraction level. another pattern p2, p1; p2 P , is represented as p1; p2 . Therefore, the set of the relationships R is represented as ² Patterns used by other patterns, patterns that are R ½ P £ P: more speci¯c, and patterns that are applied after other patterns have lower abstraction level. (P; R) is a directed graph. R+ is a transitive closure on R. R+ is de¯ned as below: We will present an intuitive explanation and a formal de¯- nition. R1 ± R2 = fhp1; p3ij9p2 2 P (hp1; p2i 2 R1 ^ hp2; p3i 2 R2)g: Only the partially-ordered relationships a®ect the abstrac- R1 = R: tion level. For instance, the Similar to relationship repre- Rn+1 = Rn ± R: sents the existence of common properties between two pat- 1 terns. Therefore, we use only the partially-ordered relation- + i R = [ R : ships to calculate the abstraction levels of patterns. i=1 2.1 Intuitive explanation of the proposed met• In addition, the set of patterns that can be retrieved tran- ric sitively from a certain pattern p is a descendant of p, repre- The reference count of a pattern is the total number of sented as D(p). The set of patterns that a certain pattern p patterns that the pattern refers transitively. The backward can be retrieved transitively are ancesters of p, represented reference count of a pattern is the total number of patterns as A(p). that refers the pattern transitively. In Figure 1, ellipses + D(p) = fp jp; p 2 P ^ hp; p i 2 R g ½ P: indicate patterns, arrows indicate partially-ordered inter- 0 0 0 f j 2 ^ h i 2 +g ½ pattern relationships. For example, the MVC pattern tran- A(p) = p0 p0; p P p0; p R P: sitively refers six patterns, so the reference count of the MVC A pattern with many ancestors tends to be a part of other patterns is six, and the backward reference count of the MVC patterns. A pattern that has many descendants tends to pattern is zero because no pattern refers the MVC pattern. In use other patterns. Where jD(p)j denotes the number of the same way, the reference count of Composite pattern is patterns included in D(p), and jA(p)j denotes same of A(p), two, and backward reference count is one.
Recommended publications
  • Ece351 Lab Manual
    DEREK RAYSIDE & ECE351 STAFF ECE351 LAB MANUAL UNIVERSITYOFWATERLOO 2 derek rayside & ece351 staff Copyright © 2014 Derek Rayside & ECE351 Staff Compiled March 6, 2014 acknowledgements: • Prof Paul Ward suggested that we look into something with vhdl to have synergy with ece327. • Prof Mark Aagaard, as the ece327 instructor, consulted throughout the development of this material. • Prof Patrick Lam generously shared his material from the last offering of ece251. • Zhengfang (Alex) Duanmu & Lingyun (Luke) Li [1b Elec] wrote solutions to most labs in txl. • Jiantong (David) Gao & Rui (Ray) Kong [3b Comp] wrote solutions to the vhdl labs in antlr. • Aman Muthrej and Atulan Zaman [3a Comp] wrote solutions to the vhdl labs in Parboiled. • TA’s Jon Eyolfson, Vajih Montaghami, Alireza Mortezaei, Wenzhu Man, and Mohammed Hassan. • TA Wallace Wu developed the vhdl labs. • High school students Brian Engio and Tianyu Guo drew a number of diagrams for this manual, wrote Javadoc comments for the code, and provided helpful comments on the manual. Licensed under Creative Commons Attribution-ShareAlike (CC BY-SA) version 2.5 or greater. http://creativecommons.org/licenses/by-sa/2.5/ca/ http://creativecommons.org/licenses/by-sa/3.0/ Contents 0 Overview 9 Compiler Concepts: call stack, heap 0.1 How the Labs Fit Together . 9 Programming Concepts: version control, push, pull, merge, SSH keys, IDE, 0.2 Learning Progressions . 11 debugger, objects, pointers 0.3 How this project compares to CS241, the text book, etc. 13 0.4 Student work load . 14 0.5 How this course compares to MIT 6.035 .......... 15 0.6 Where do I learn more? .
    [Show full text]
  • Design Pattern Interview Questions
    DDEESSIIGGNN PPAATTTTEERRNN -- IINNTTEERRVVIIEEWW QQUUEESSTTIIOONNSS http://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm Copyright © tutorialspoint.com Dear readers, these Design Pattern Interview Questions have been designed specially to get you acquainted with the nature of questions you may encounter during your interview for the subject of Design Pattern. As per my experience good interviewers hardly plan to ask any particular question during your interview, normally questions start with some basic concept of the subject and later they continue based on further discussion and what you answer: What are 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 over quite a substantial period of time. 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 which initiated the concept of Design Pattern in Software development. These authors are collectively known as Gang of Four GOF. Name types of Design Patterns? Design patterns can be classified in three categories: Creational, Structural and Behavioral patterns. Creational Patterns - These design patterns provide a way to create objects while hiding the creation logic, rather than instantiating objects directly using new opreator. 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.
    [Show full text]
  • Behavioral Patterns
    Behavioral Patterns 101 What are Behavioral Patterns ! " Describe algorithms, assignment of responsibility, and interactions between objects (behavioral relationships) ! " Behavioral class patterns use inheritence to distribute behavior ! " Behavioral object patterns use composition ! " General example: ! " Model-view-controller in UI application ! " Iterating over a collection of objects ! " Comparable interface in Java !" 2003 - 2007 DevelopIntelligence List of Structural Patterns ! " Class scope pattern: ! " Interpreter ! " Template Method ! " Object scope patterns: ! " Chain of Responsibility ! " Command ! " Iterator ! " Mediator ! " Memento ! " Observer ! " State ! " Strategy ! " Visitor !" 2003 - 2007 DevelopIntelligence CoR Pattern Description ! " Intent: Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. ! " AKA: Handle/Body ! " Motivation: User Interfaces function as a result of user interactions, known as events. Events can be handled by a component, a container, or the operating system. In the end, the event handling should be decoupled from the component. ! " Applicability: ! " more than one object may handle a request, and the handler isn't known a priori. ! " Want to issue a request to one of several objects without specifying the receiver !" 2003 - 2007 DevelopIntelligence CoR Real World Example ! " 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. ! " Mechanical coin sorting banks use the Chain of Responsibility. Rather than having a separate slot for each coin denomination coupled with receptacle for the denomination, a single slot is used. When the coin is dropped, the coin is routed to the appropriate receptacle by the mechanical mechanisms within the bank.
    [Show full text]
  • Design Patterns (Part 3)
    Design patterns (part 3) CSE 331 University of Washington Michael Ernst Outline Introduction to design patterns Creational patterns (constructing objects) Structural patterns (controlling heap layout) ⇒Behavioral patterns (affecting object semantics) Composite pattern Composite permits a client to manipulate either an atomic unit or a collection of units in the same way Good for dealing with part-whole relationships Composite example: Bicycle • Bicycle – Wheel • Skewer • Hub • Spokes • Nipples • Rim • Tape • Tube • Tire – Frame – Drivetrain – ... Methods on components class BicycleComponent { int weight (); float cost (); } class Skewer extends BicycleComponent { float price ; float cost () { return price; } } class Wheel extends BicycleComponent { float assemblyCost ; Skewer skewer ; Hub hub ; ... float cost () { return assemblyCost + skewer.cost() + hub.cost() + ...; } } Composite example: Libraries Library Section (for a given genre) Shelf Volume Page Column Word Letter interface Text { String getText (); } class Page implements Text { String getText () { ... return the concatenation of the column texts ... } } Traversing composites Goal: perform operations on all parts of a composite Representing Java code x = foo * b + c / d; = x + * / foo b c d Abstract syntax tree (AST) for Java code class PlusOp extends Expression { // + operation Expression leftExp ; Expression rightExp ; } class VarRef extends Expression { // variable reference String varname ; } class EqualOp extends Expression { // equality test a==b; Expression lvalue ; //
    [Show full text]
  • Automatic Generation of Truffle-Based Interpreters for Domain
    Automatic generation of Truffle-based interpreters for Domain-Specific Languages Manuel Leduc, Gwendal Jouneaux, Thomas Degueule, Gurvan Le Guernic, Olivier Barais, Benoit Combemale To cite this version: Manuel Leduc, Gwendal Jouneaux, Thomas Degueule, Gurvan Le Guernic, Olivier Barais, et al.. Automatic generation of Truffle-based interpreters for Domain-Specific Languages. The Journal of Object Technology, Chair of Software Engineering, 2020, 19 (2), pp.1-21. 10.5381/jot.2020.19.2.a1. hal-02395867v2 HAL Id: hal-02395867 https://hal.inria.fr/hal-02395867v2 Submitted on 21 Feb 2021 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Journal of Object Technology Published by AITO — Association Internationale pour les Technologies Objets http://www.jot.fm/ Automatic generation of Truffle-based interpreters for Domain-Specific Languages Manuel Leduca Gwendal Jouneauxa Thomas Degueuleb Gurvan Le Guernicc Olivier Baraisa Benoit Combemalead a. Univ. Rennes, Inria, CNRS, IRISA, France b. Univ. Bordeaux, Bordeaux INP, CNRS, LaBRI, UMR5800, F-33400 Talence, France c. DGA MI, Bruz, France d. Univ. Toulouse, IRIT, France Abstract Numerous language workbenches have been proposed over the past decade to ease the definition of Domain-Specific Languages (DSLs).
    [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]
  • Table of Contents
    Table of Contents ± -—T^jTp^om Object-Oriented to Functional Programming 5 Chajava- an introduction 5 java programming paradigms 6 CO imperative programming CD Real-life imperative example Object-oriented paradigm 7 Objects and classes 7 Encapsulation 7 Abstraction 8 Inheritance 8 Polymorphism 9 Declarative programming 10 Functional programming 11 Working with collections versus working with streams 11 An introduction to Unified Modeling Language 12 Class relations 14 Generalization 15 Realization 15 Dependency 16 Association 16 Aggregation 16 Composition 17 Design patterns and principles 17 Single responsibility principle 18 Open/closed principle 20 Liskov Substitution Principle 20 Interface Segregation Principle 22 Dependency inversion principle 23 Summary 24 Chapter 2: Creational Patterns 27 Singleton pattern 27 Synchronized singletons 29 Synchronized singleton with double-checked locking mechanism 30 Lock-free thread-safe singleton 30 tu * y and lazy loacling 31 i he factory pattern 31 Simple factory pattern 32 Table of Contents Static factory 33 Simple factory with class registration using reflection 34 Simple factory with class registration using Product.newlnstance 35 Factory method pattern 36 Anonymous concrete factory 38 Abstract factory 38 Simple factory versus factory method versus abstract factory 40 Builder pattern 40 Car builder example 41 Simplified builder pattern 43 Anonymous builders with method chaining 44 Prototype pattern 45 Shallow clone versus deep clone Object pool pattern Summary аэоэсБ Chapter 3: Behavioral Patterns
    [Show full text]
  • First-Class Functions and Patterns
    First-class Functions and Patterns Corky Cartwright Stephen Wong Department of Computer Science Rice University 1 Encoding First-class Functions in Java • Java methods are not data values; they cannot be used as values. • But java classes include methods so we can implicitly pass methods (functions) by passing class instances containing the desired method code. • Moreover, Java includes a mechanism that closes over the free variables in the method definition! • Hence, first-class functions (closures) are available implicitly, but the syntax is wordy. • Example: Scheme map 2 Interfaces for Representing Functions For accurate typing, we need different interfaces for different arities. With generics, we can define parameterized interfaces for each arity. In the absence of generics, we will have to define separate interfaces for each desired typing. map example: /** The type of unary functions in Object -> Object. */ interface Lambda { Object apply(Object arg); } abstract class ObjectList { ObjectList cons(Object n) { return new ConsObjectList(n, this); } abstract ObjectList map(Lambda f); } ... 3 Representing Specific Functions • For each function that we want to use a value, we must define a class, preferably a singleton. Since the class has no fields, all instances are effectively identical. • Defining a class seems unduly heavyweight, but it works in principle. • In OO parlance, an instance of such a class is called a strategy. • Java provides a lightweight notation for singleton classes called anonymous classes. Moreover these classes can refer to fields and final method variables that are in scope. In DrJava language levels, all variables are final. final fields and variables cannot be rebound to new values after they are initially defined (immutable).
    [Show full text]
  • Design Patterns Mock Test
    DDEESSIIGGNN PPAATTTTEERRNNSS MMOOCCKK TTEESSTT http://www.tutorialspoint.com Copyright © tutorialspoint.com This section presents you various set of Mock Tests related to Design Patterns Framework. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself. DDEESSIIGGNN PPAATTTTEERRNNSS MMOOCCKK TTEESSTT IIII Q 1 - Which of the following describes the Composite pattern correctly? A - This pattern builds a complex object using simple objects and using a step by step approach. B - This pattern is used where we need to treat a group of objects in similar way as a single object. C - This pattern hides the complexities of the system and provides an interface to the client using which the client can access the system. D - This pattern is primarily used to reduce the number of objects created and to decrease memory footprint and increase performance. Q 2 - Which of the following describes the Decorator pattern correctly? A - This pattern allows a user to add new functionality to an existing object without altering its structure. B - This pattern is used where we need to treat a group of objects in similar way as a single object. C - This pattern hides the complexities of the system and provides an interface to the client using which the client can access the system. D - This pattern is primarily used to reduce the number of objects created and to decrease memory footprint and increase performance. Q 3 - Which of the following describes the Facade pattern correctly? A - This pattern allows a user to add new functionality to an existing object without altering its structure.
    [Show full text]
  • Non-Software Examples of Software Design Patterns Автор: Michael Duell
    Non-Software Examples of Software Design Patterns Автор: Michael Duell. Хорошая, хоть и старая (97 год) статья в которой приведены примеры применения паттернов в вещах, которые не имеют отношения к разработке. Такой подход отлично иллюстрирует паттерны и делает их более доступными для понимания. Например отлично показан паттерн Фасад: интерфейсы офисных устройств можно сильно упростить с помощью секретарши. Или например паттерн Бридж, который показан на примере выключателя которым можно управлять лампочкой, вентилятором или любым другим прибором. Non-Software Examples of Software Design Patterns by Michael Duell Abstract Software design patterns have roots in the architectural patterns of Christopher Alexander, and in the object movement. According to Alexander, patterns repeat themselves, since they are a generic solution to a given system of forces. The object movement looks to the real world for insights into modeling software relationships. With these dual roots, it seems reasonable that software design patterns should be repeated in real world objects. This paper presents a real world, non software instance of each design pattern from the book, Design Patterns - Elements of Reusable Object-Oriented Software [13]. The paper also discusses the implications of non-software examples on the communicative power of a pattern language, and on design pattern training. 1. Introduction Within the software industry, a growing community of patterns proponents exists. The roots of the patterns movement are found in the writings of architect Christopher Alexander, who describes a pattern as a generic solution to a given system of forces in the world [1]. Alexander's patterns can be observed in everyday structures. Each pattern in A Pattern Language[2] includes a picture of an archetypal example of the pattern.
    [Show full text]
  • Structuring Languages As Object-Oriented Libraries
    UvA-DARE (Digital Academic Repository) Structuring languages as object-oriented libraries Inostroza Valdera, P.A. Publication date 2018 Document Version Final published version License Other Link to publication Citation for published version (APA): Inostroza Valdera, P. A. (2018). Structuring languages as object-oriented libraries. General rights It is not permitted to download or to forward/distribute the text or part of it without the consent of the author(s) and/or copyright holder(s), other than for strictly personal, individual use, unless the work is under an open content license (like Creative Commons). Disclaimer/Complaints regulations If you believe that digital publication of certain material infringes any of your rights or (privacy) interests, please let the Library know, stating your reasons. In case of a legitimate complaint, the Library will make the material inaccessible and/or remove it from the website. Please Ask the Library: https://uba.uva.nl/en/contact, or a letter to: Library of the University of Amsterdam, Secretariat, Singel 425, 1012 WP Amsterdam, The Netherlands. You will be contacted as soon as possible. UvA-DARE is a service provided by the library of the University of Amsterdam (https://dare.uva.nl) Download date:04 Oct 2021 Structuring Languages as Object-Oriented Libraries Structuring Languages as Object-Oriented Libraries ACADEMISCH PROEFSCHRIFT ter verkrijging van de graad van doctor aan de Universiteit van Amsterdam op gezag van de Rector Magnificus prof. dr. ir. K. I. J. Maex ten overstaan van een door het College voor Promoties ingestelde commissie, in het openbaar te verdedigen in de Agnietenkapel op donderdag november , te .
    [Show full text]
  • Design Patterns (Part 3)
    Design patterns (part 3) CSE 331 University of Washington Outline Introduction to design patterns Creational patterns (constructing objects) Structural patterns (controlling heap layout) ⇒Behavioral patterns (affecting object semantics) Composite pattern • Composite permits a client to manipulate either an atomic unit or a collection of units in the same way • Good for dealing with part-whole relationships Composite example: Bicycle • Bicycle – Wheel • Skewer • Hub • Spokes • Nipples • Rim • Tape • Tube • Tire – Frame – Drivetrain – ... Methods on components class BicycleComponent { int weight(); float cost (); } class Skewer extends BicycleComponent { float price; float cost () { return price; } } class Wheel extends BicycleComponent { float assemblyCost; Skewer skewer; Hub hub; ... float cost () { return assemblyCost + skewer.cost() + hub.cost() + ...; } } Composite example: Libraries Library Section (for a given genre) Shelf Volume Page Column Word Letter interface Text { String getText (); } class Page implements Text { String getText () { ... return the concatenation of the column texts ... } } Traversing composites Goal: perform operations on all parts of a composite Abstract syntax tree (AST) for Java code class PlusOp extends Expression { // + operation Expression leftExp; Expression rightExp; } class VarRef extends Expression { // variable reference String varname; } class EqualOp extends Expression { // equality test a==b; Expression lvalue; // left-hand side; "a" in "a==b" Expression rvalue; // right-hand side; "b" in "a==b"
    [Show full text]