ECE 452 / CS 446 / SE464 Design Patterns: Part 2 - Answers A Tutorial By Peter Kim Partially based on the tutorial by Michał Antkiewicz.

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Creational Design Patterns. Creational DP: Abstracts the instantiation process Helps make a system independent of how objects are created, composed, represented.
Goals Give you a feeling of what Eclipse is.
Design Patterns David Talby. This Lecture Representing other objects Proxy, Adapter, Façade Re-routing method calls Chain of Responsibility Coding partial.
Patterns Lecture 2. Singleton Ensure a class only has one instance, and provide a global point of access to it.
IEG3080 Tutorial 7 Prepared by Ryan.
Design Patterns CS is not simply about programming
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Views Dwight Deugo Nesa Matic
1 Standard Widget Toolkit. 2 SWT l a widget toolkit for Java developers l provides a portable API and tight integration with the underlying native OS.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
On Platform-Plugin Architecture Take Eclipse as an Example 魏恒峰.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
Design Patterns Standardized Recurring model Fits in many location Opposite of customization Fundamental types of pattern Choose and use as desired and.
Singleton Christopher Chiaverini Software Design & Documentation September 18, 2003.
Design Patterns.
JFace 吳昆澤. UI framework for plug-ins JFace provides classes for handling common UI programming tasks: Viewers handle the drudgery of populating, sorting,
Design Dan Fleck CS 421 George Mason University. What is the design phase? Analysis phase describes what the system should do Analysis has provided a.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
Writing Widgets & Custom Script API for BOY Xihui Chen
CSSE 374: Introduction to Gang of Four Design Patterns
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
Ontology Engineering and Plugin Development with the NeOn Toolkit Plug-in Development for the NeOn Toolkit June 1st, 2008 Michael Erdmann, Peter Haase,
1 21 COP 3540 Data Structures with OOP Overview: Chapter 1.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
CPSC 372 John D. McGregor Module 4 Session 1 Design Patterns.
ECE 452 / CS 446 / SE464 Design Patterns: Part 2 - Questions A Tutorial By Peter Kim Partially based on the tutorial by Michał Antkiewicz.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
GoF: Document Editor Example Rebecca Miller-Webster.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
CS 4233 Review Feb February Review2 Outline  Previous Business – My.wpi.edu contains all grades to date for course – Review and contact.
Design Patterns Yonglei Tao. Design Patterns  A design pattern describes a recurring design problem, a solution, and the context in which that solution.
CPSC 871 John D. McGregor Module 5 Session 1 Design Patterns.
Programmeerimine Delphi keskkonnas MTAT Programmeerimine Delphi keskkonnas MTAT Jelena Zaitseva
The Singleton Pattern SE-2811 Dr. Mark L. Hornick 1.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Gang of Four Patterns 23 total 15 useful How are they different from GRASP Patterns?
Design Patterns David Talby. This Lecture Re-routing method calls Chain of Responsibility Coding partial algorithms Template Method The Singleton Pattern.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Design Patterns Introduction
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
Java Design Patterns Java Design Patterns. What are design patterns? the best solution for a recurring problem a technique for making code more flexible.
The Visitor Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
StarBuzz Coffee Recipe Boil some water Brew coffee in boiling water Pour coffee in cup Add sugar and milk Tea Recipe Boil some water Steep tea in boiling.
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
Design Patterns: MORE Examples
Goals Give you a feeling of what Eclipse is.
Chapter 10 Design Patterns.
MPCS – Advanced java Programming
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
Advanced Programming Behnam Hatami Fall 2017.
Singleton Pattern Pattern Name: Singleton Pattern Context
Singleton design pattern
CS 350 – Software Design Singleton – Chapter 21
Design pattern Lecture 6.
Plug-In Architecture Pattern
Presentation transcript:

ECE 452 / CS 446 / SE464 Design Patterns: Part 2 - Answers A Tutorial By Peter Kim Partially based on the tutorial by Michał Antkiewicz

Eclipse and Patterns ● Tutorial based on – Erich Gamma, Kent Beck, “Contributing to Eclipse, Principles, Patterns and Plug-ins”, Addison-Wesley, 2004 – Rod Waldhoff’s blog, Implementing the Singleton Pattern in Java, plementingTheSingletonPatternInJava.html ● Extensive use of design patterns ● Plug-in architecture

Problem 1: Abstract Syntax Tree Analysis ● In Java Development Tools (JDT) Java code is parsed and represented internally as an abstract syntax tree ● ASTNode represents any node in an abstract syntax tree ● Problem: how to encapsulate various AST analysis algorithms such that it is easy to add new algorithms. Assume that the presented class hierarchy is stable ● Note that analysis algorithm needs to maintain certain information during tree traversal

Answer 1: AST Analysis - Visitor

Problem 2: Connecting Viewer to Model ● JFace plug-in provides viewers for standard SWT widgets such as tree, table and list. The viewer's main responsibility is to populate a widget with objects from the model. To do that, a viewer needs to traverse the model and retrieve strings (labels) and icons that the widget can present ● On the other hand a viewer is completely independent from the model it is displaying and the model knows nothing about being displayed (that means viewer and model interfaces are incompatible) ● Good solution is Model-View-Controller pattern ● Which pattern is the most appropriate to connect the viewer (controller) with any model? (viewer needs information such as children, parent, image, text)

Answer 2: Connecting Viewer to Model - Adapter ● Concrete adapters MyModelLabelProvider and MyModelTreeContentProvider are domain specific (know how to access information from the concrete model) ● Adapters implement interfaces necessary for the viewer to operate independently from particular model it is displaying

Problem 3: Workbench ● In Eclipse, the workbench class represents the top of the Eclipse user interface. Its primary responsibility is the management of workbench windows, dialogs, wizards, and other workbench-related windows. ● What pattern can be used to – ensure no one can create instances of Workbench, – only one instance of Workbench is accessible globally, – ensure, there can be at most one instance. ● Present appropriate fragments of code

Answer 3: Workbench - Singleton ● Private constructor forbids direct creation of instances ● getInstance() returns the one and only instance ● Public createAndRunWorkbench(...) used by Platform calls private constructor, which ensures only one instance is created

Problem 4: Subclassing Singletons Workbench is to have subclasses, such as EnterpriseWorkbench (for high-end business use) and LightweightWorkbench (for novice use). Assume that the subclass may be chosen at any point in time prior to accessing the Workbench singleton. Show two ways of subclassing the singleton and explain a disadvantage of each way.

Answer 4a): Using a registry public class Workbench { static protected Dictionary registry = new Hashtable(); static { Workbench w = new Workbench(); registry.put(w.getClass().getName(), w); } protected Workbench() { … } static public Workbench getInstance(String workbenchClassName) { return (Workbench)(registry.get(workbenchClassName)); } … } Before runtime, each subclass of Workbench is placed into the registry. This is the only place to call the constructor. E.g. LightweightWorkbench would do Workbench w = new LightweightWorkbench(); (note, in Java, the class loading sequence seems to be non- detemrinistic…may have to register all direct/indirect subclasses of Workbench at once (through reflection, for example). Workbench.getInstance(Environment.get(“WORKBENCH”).method(); At runtime, the particular singleton desired is referenced by its class name. Disadvantage: a singleton for every Workbench class is created, but only one is actually used.

Answer 4b): Using AbstractFactory+Wrapper public interface WorkbenchFactory { public Workbench createWorkbench(); } final public class WorkbenchWrapper { private static Workbench workbench; private static WorkbenchFactory factory; public static void setFactory(WorkbenchFactory factory) { this.factory = factory; } public static Workbench getInstance() { if(workbench == null) workbench = factory.createWorkbench(); return workbench; } … } Different implementations of WorkbenchFactory create an instance of different subclasses of Workbench WorkbenchWrapper used to ensure single instance of Workbench Disadvantages: Larger code overhead and constructor of a Workbench class cannot be private (due to WorkbenchFactory) Loose coupling between subclass management and singleton enforcement/access

Problem 5: Proxy Give 3 types of situations where the Proxy design pattern may be applicable and provide an example for each. Think of at least one situation that’s relevant to your project.

Answer 5 CallManagerIHWResources HWResourcesHWResourcesProxy getIPExtMapping(): Dictionary isDirty(): boolean getIPExtMapping(): Dictionary isDirty(): boolean if(hwResources.isDirty()) hwResources = load(); return hwResources.getIPExtMapping(); *1 Cardinality is important! Performance (e.g. data caching) Space management (e.g. symbolic file links) Security (e.g. proxy controls access to the real subject) getIPExtMapping(): Dictionary isDirty(): boolean