UML & Strategy Pattern - University Of California, San Diego

5m ago
7 Views
1 Downloads
691.22 KB
16 Pages
Last View : 13d ago
Last Download : 3m ago
Upload by : Milo Davies
Transcription

Discussion 11/2/2016 UML & Strategy Pattern

UML – What and Why? “Universal Modeling Language” Emerged in the mid 90’s to standardize software design notation Language-independent visual representation of object-based software design Methods representing both structural and behavioral design of software* *These slides only cover structural UML.

UML Notation – Classes Name Access Level Type Can be followed by “ : Type “ to denote return type. This method is void.

UML Notation – Inheritance (Is-A)

Example (1.1) – Simple Animals Animals as OBJECTS (Instantiated Classes)

UML Notation – Interfaces * Key distinction between abstract classes and interfaces: abstract classes are realized via inheritance, interfaces are realized via implementation. Interfaces should be used used to define behaviors which classes implement.

Example (1.2) – Simple Animals Notice dashed line for implementation

UML Notation – Aggregation, Composition, and Association (Has-A) Aggregation (ClassA contains ClassB) Composition (ClassA contains ClassB) Association (Bi-Directional) Multiplicity * 1 n Any number Exactly 1 Exactly n 0.1 1.* n.m Zero OR 1 One or more Any value n through m

Example (2.1) – Airports & Universities Here a “route” is a path flown by a passenger (ex: San Diego to New York), where a route is an aggregation of direct flights. You could take a direct flight or have a connecting flight in Chicago. Each flight only has one plane for a specific gate and time, but a plane may have multiple flights. A university is composed of departments, which will cease to exist if the university is closed. In the previous example, a flight will still exist even if it is not encapsulated by a route.

Strategy Pattern Strategy Goals (1) Define a family of algorithms (2) Encapsulate each algorithm (3) Make algorithms interchangeable within family

Strategy – In UML

Example (3.1) Strategy Situations: Pitcher

Example (3.2) Strategy Situations: Audio Playback

In Java: Strategy & Concrete Strategies // encapsulates family of algorithms public interface Strategy { public void algorithm(); } // a strategy for implementing an algorithm public class ConcreteStrategyA implements Strategy { // implementation of the algorithm public void algorithm() { // do stuff one way System.out.println("using strategy A"); return; } } // a second strategy for implementing an algorithm public class ConcreteStrategyB implements Strategy { // implementation of the algorithm public void algorithm() { // do stuff another way System.out.println("using strategy B"); return; } }

In Java: Context public class Context { // interface to set strategy public void setStrategy(Strategy strategy) { s strategy; return; } // execute algorithm public void execute() { s.algorithm(); return; } // NOTE: set strategy before using private Strategy s; }

In Java: Client Code public class Test { // demo the strategy public static void main(String[] args) { Context c new Context(); // set and use strategy A c.setStrategy(new ConcreteStrategyA()); c.execute(); // set and use strategy B c.setStrategy(new ConcreteStrategyB()); c.execute(); // . and let's go back to strategy A c.setStrategy(new ConcreteStrategyA()); c.execute(); return; }

// a strategy for implementing an algorithm public class ConcreteStrategyA implements Strategy {// implementation of the algorithm public void algorithm() {// do stuff one way System.out.println("using strategy A"); return;}} // a second strategy for implementing an algorithm public class ConcreteStrategyB implements Strategy

Related Documents:

PSI AP Physics 1 Name_ Multiple Choice 1. Two&sound&sources&S 1∧&S p;Hz&and250&Hz.&Whenwe& esult&is:& (A) great&&&&&(C)&The&same&&&&&

Argilla Almond&David Arrivederci&ragazzi Malle&L. Artemis&Fowl ColferD. Ascoltail&mio&cuore Pitzorno&B. ASSASSINATION Sgardoli&G. Auschwitzero&il&numero&220545 AveyD. di&mare Salgari&E. Avventurain&Egitto Pederiali&G. Avventure&di&storie AA.&VV. Baby&sitter&blues Murail&Marie]Aude Bambini&di&farina FineAnna

The program, which was designed to push sales of Goodyear Aquatred tires, was targeted at sales associates and managers at 900 company-owned stores and service centers, which were divided into two equal groups of nearly identical performance. For every 12 tires they sold, one group received cash rewards and the other received

OOAD with UML Object Oriented Analysis and Design Using the UML . 2 UML Applied - Object Oriented Analysis and Design using the UML . . Objects 23 Terminology 24 The Object Oriented Strategy 24 Summary 25 AN OVERVIEW OF THE UML 26 The Use Case Diagram 27 The Class Diagram 28

to Design Patterns Part III Modeling Behavior: State Machines etc. Literature on UML §Official standard documents by OMG: www.omg.org, www.uml.org §Current version is UML 2.0 (2004/2005) §OMG documents: UML Infrastructure, UML Superstructure §Books: Pfleeger: Software Engineering 3rd ed., 2005 (mostly Chapter 6) Rumbaugh, Jacobson, Booch:

Praise for UML Distilled “UML Distilled remains the best introduction to UML notation. Martin’s agile and pragmatic approach hits the sweet spot, and I wholeheartedly recommend it!” —Craig Larman Author of Applying UML and Patterns “Fowler cuts through the complexity of UML to get users started quickly.”

UML unifies a number of visual design methodologies in software engineering, business modeling and management, database design, and others. UML Class diagrams are a subset of UML that is suitable for conceptual modeling of classes and databases Most used type of UML diagrams UML is also a graphic language for modeling dynamic aspects of a

18/12/06 Introduction à UML 4 Le méta-modèle UML UML : langage permettant de créer des modèles, UML : modélisation des modèles, un méta-modèle. Le méta-modèle UML est en 4 couches: (M3) métamétamodèle : (concept de métaclasse) Définit le langage pour la spécification des metamodèles, (M2) métamodèle : (concept de classe)