Toronto ECE 450 - Lecture 4 - Topics on Design Patterns

Unformatted text preview:

Spring 2005 ECE450H1S Software Engineering IILecture 4Topics onDesign PatternsCopyright © Yijun Yu, 2005Spring 2005 ECE450H1S Software Engineering IILast tutorial …OpenOME, a requirements engineering tool• We explained the requirements, design andimplementation of the tool. We also pointed outhow to contribute to the tool.• After the tutorial– I posted the source code to the Sourceforge– You can download the branch “ECE450-v1” from theCVS, you can also download the packed SDK• The design of OpenOME has used some designpatterns, such as Observer (MVC), Visitor,Command …• Hope you can smell right places to apply thedesign patterns after the lecture …Spring 2005 ECE450H1S Software Engineering IILast lecture …Reengineering Engineering• Goal oriented requirements engineeringleads to a better understanding of quality• Design Patterns can be considered as theoperationalization of the qualityimprovementsTwo papers in the literature linkrequirements with patterns:• Ladan Tahvildari, Kostas Kontogiannis: Improving design qualityusing meta-pattern transformations: a metric-based approach.Journal of Software Maintenance 16(4-5): 331-361 (2004)• Ladan Tahvildari, Kostas Kontogiannis, John Mylopoulos: “Quality-driven software re-engineering”. Journal of Systems and Software66(3): 225-239 (2003)Spring 2005 ECE450H1S Software Engineering IIToday …Topics on Design Patterns1. What are design patterns?2. How are they classified?3. How to apply design patterns?4. How to identify design patterns?5. Which qualities are related to the design patterns?6. SummaryReferenceThe (Gang of Four) book:Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides.Design Patterns, Elements of Reusable Object-OrientedSoftware. 1995.Spring 2005 ECE450H1S Software Engineering II1. What are design patterns?What are the patterns?• Patterns in the textile (cloths, tiles)• Patterns in visualizationsIt is a recurring phenomenon …Y. Yu, K. Beyls, and E.H. D'Hollander. Visualizing the impact of thecache on program execution. In Proceedings of Fifth InternationalConference on Information Visualization, pages 336-341, London,England, July 2001. IEEE Computer Society.Spring 2005 ECE450H1S Software Engineering IIPatterns in cache behaviourSpring 2005 ECE450H1S Software Engineering IIPatterns in Design• Architect: Christopher Alexander• A Pattern Language, and A Timeless Wayof Building݁ড়ศˈᵁᎲHanchow, ChinaPisa towerPisa, ItalyEiffel towerParis, FranceCN TowerToronto, CanadaPearl TowerShanghai, ChinaSpring 2005 ECE450H1S Software Engineering IIDesign Patterns• (Design) patterns are devices that allowprograms to share knowledge about theirdesign. It is reusable when the same kindof problem reoccur …• When there are many reusable patterns,they must be classified in a commonlanguage to effectively apply the pattern tosimilar problems again …Spring 2005 ECE450H1S Software Engineering II2. Catalogue of design patterns• CreationalAbstract Factory, Builder, Factory, LazyInitialization, Prototype, Singleton, etc.• StructuralAdapter, Bridge, Composite, Container,Decorator, Delegation, Extensibility, Façade,Flyweight, Interface, Pipes and filters, Proxy, etc.• BehaviouralChain of Responsibility, Command, EventListener, Immutable, Interpreter, Iterator,Mediator, Memento, Observer, State, Strategy,Template Method, Visitor, etc.Spring 2005 ECE450H1S Software Engineering IIA pattern language• Pattern language: “the pattern of patterns”provides a template for patterns– The motivation or context that this pattern applies to.– Prerequisites that should be satisfied before decidingto use a pattern.– A description of the program structure that the patternwill define.– A list of the participants needed to complete a pattern.– Consequences of using the pattern...both positive andnegative.– Examples!Spring 2005 ECE450H1S Software Engineering IIThe GOF pattern language• Pattern Name and Classification: Every pattern should have a descriptive and unique name thathelps in identifying and referring to it. Additionally, the pattern should be classified according to aclassification such as the one described earlier. This classification helps in identifying the use ofthe pattern.• Intent: This section should describe the goal behind the pattern and the reason for using it. Itresembles the problem part of the pattern.• Also Known As: A pattern could have more than one name. These names should bedocumented in this section.• Motivation: This section provides a scenario consisting of a problem and a context in which thispattern can be used. By relating the problem and the context, this section shows when this patternis used.• Applicability: This section includes situations in which this pattern is usable. It represents thecontext part of the pattern.• Structure: A graphical representation of the pattern.Class diagrams and Interaction diagramscan be used for this purpose.• Participants: A listing of the classes and objects used in this pattern and their roles in the design.• Collaboration: Describes how classes and objects used in the pattern interact with each other.• Consequences: This section describes the results, side effects, and trade offs caused by usingthis pattern.• Implementation: This section describes the implementation of the pattern, and represents thesolution part of the pattern. It provides the techniques used in implementing this pattern, andsuggests ways for this implementation.• Sample Code: An illustration of how this pattern can be used in a programming language• Known Uses: This section includes examples of real usages of this pattern.• Related Patterns: This section includes other patterns that have some relation with this pattern,so that they can be used along with this pattern, or instead of this pattern. It also includes thedifferences this pattern has with similar patterns.Spring 2005 ECE450H1S Software Engineering II3. How to apply design patterns? ExampleFactory method• Constructing objects based on some inputsuch that functions inside the objectsdepend upon the input.• Consider as an example a class to readimage files and make thumbnails out ofthem– A bad example– An improved one– The Use of the patternSpring 2005 ECE450H1S Software Engineering IIBad one1. public class ImageReader {2. private int fileType;3. private String fileContents;4. private byte[] decodedImage;5. public ImageReader( InputStream in ) {6.


View Full Document
Download Lecture 4 - Topics on Design Patterns
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 4 - Topics on Design Patterns and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 4 - Topics on Design Patterns 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?