K. Stirewalt CSE 335: Software Design Synthetic OO Design Concepts & Reuse Lecture 5: Mixins and reusable strategies Topics: – More on the use of mixins.

Slides:



Advertisements
Similar presentations
K. Stirewalt CSE 335: Software Design Synthetic OOD concepts and reuse Lecture 4: Separation of concerns Topics: –Complex concern: Memory management –
Advertisements

Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
1 CS1001 Lecture Overview Homework 3 Homework 3 Project/Paper Project/Paper Object Oriented Design Object Oriented Design.
Slide 1 Systems Analysis & Design CS183 Spring Semester 2008 Dr. Jonathan Y. Clark Course Website:
R R R CSE870: Advanced Software Engineering: Frameworks (Cheng, Sp2003)1 Frameworks A Brief Introduction.
K. Stirewalt CSE 335: Software Design Synthetic OO Design Concepts & Reuse Lecture 1: Program fragments and abstract classes Topics: –Economics of software.
K. Stirewalt CSE 335: Software Design Synthetic OO Design Concepts & Reuse Lecture 2: Abstract classes and composite structures Topics: –Elaboration of.
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Object-oriented concepts.
K. Stirewalt CSE 335: Software Design Synthetic OO Design Concepts & Reuse Lecture 7: Roles and Collaborations Topics: – Interactive applications, their.
K. Stirewalt CSE 335: Software Design Outline of course topics Foundational OO concepts Synthetic concepts: –Program families, program fragments, and abstract.
Vrije Universiteit amsterdamPostacademische Cursus Informatie Technologie Themes and Variations abstraction -- the object metaphor modeling -- understanding.
K. Stirewalt CSE 335: Software Design Software Architecture and Larger System Design Issues Lecture 3: Synchronization Topics: –Concurrent access to shared.
K. Stirewalt CSE 335: Software Design Software architecture and larger system design issues Lecture 1: Simulating concurrency Topics: –High-level software.
K. Stirewalt CSE 335: Software Design Synthetic OO Design Concepts & Reuse Lecture 5: Mixins and reusable strategies Topics: – More on the use of mixins.
K. Stirewalt CSE 335: Software Design Software Architecture and Larger System Design Issues Lecture 4: Life cycles of concurrent actors Topics: –The “life.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
CSE 332: C++ templates and generic programming I Motivation for Generic Programming in C++ We’ve looked at procedural programming –Reuse of code by packaging.
Collaborative Systems Developing Collaborative Systems with a Reuse Driven Process.
Programming With Java ICS201 University Of Hail1 Chapter 12 UML and Patterns.
Introduction to Object-oriented Programming CSIS 3701: Advanced Object Oriented Programming.
Software Engineering Muhammad Fahad Khan
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 18 Slide 1 Software Reuse.
LAYING OUT THE FOUNDATIONS. OUTLINE Analyze the project from a technical point of view Analyze and choose the architecture for your application Decide.
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
Design Patterns.
1 CSC 427: Data Structures and Algorithm Analysis Fall 2011 See online syllabus (also available through BlueLine): Course goals:
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
Ceg860 (Prasad)L6MR1 Modularity Extendibility Reusability.
Introductory Software Engineering with a Focus on Dependency Management Christine Hofmeister.
Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)
ISP666 MVC & Design Patterns. Outline Review Event Programming Model Model-View-Controller Revisit Simple Calculator Break Design Patterns Exercise.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 18 Slide 1 Software Reuse.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Mediator Pattern and Multiuser Protection Billy Bennett June 8 th, 2009.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
CS 350 – Software Design The Strategy Pattern – Chapter 9 Changes to software, like other things in life, often focus on the immediate concerns and ignore.
Cohesion and Coupling CS 4311
CSE 303 – Software Design and Architecture LECTURE 4.
K. Stirewalt CSE 335: Software Design Synthetic OO Design Concepts & Reuse Lecture 1: Program fragments and abstract classes Topics: –Economics of software.
L8 - March 28, 2006copyright Thomas Pole , all rights reserved 1 Lecture 8: Software Asset Management and Text Ch. 5: Software Factories, (Review)
Genericity Ranga Rodrigo Based on Mark Priestley's Lectures.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Prepared by: Elsy Torres Shajida Berry Siobhan Westby.
CSE 1301 Lecture 5 Writing Classes Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
OOAD Unit – I OBJECT-ORIENTED ANALYSIS AND DESIGN With applications
K. Stirewalt CSE 335: Software Design Synthetic OO Design Concepts & Reuse Lecture 8: Modeling & documenting collaborations Topics: –Synthesis of multiple.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
1 CSC 427: Data Structures and Algorithm Analysis Fall 2006 See online syllabus (also available through Blackboard): Course goals:
Billy Bennett June 22,  Intent Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.
Foundations: Language mechanisms and primitive OO concepts Lecture 1: Classification and Inheritance Michigan State University Spring 2008 E. Kraemer Notes.
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Collaborative Systems Developing Collaborative Systems with a Reuse Driven Process.
Design Patterns. Outline Purpose Purpose Useful Definitions Useful Definitions Pattern Overview Pattern Overview.
Module 9. Dealing with Generalization Course: Refactoring.
K. Stirewalt CSE 335: Software Design Synthetic OO Design Concepts & Reuse Lecture 1: Program fragments and abstract classes Topics: –Economics of software.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Templates Linked Lists.
Design Patterns: MORE Examples
Introduction to Design Patterns
CS 350 – Software Design The Strategy Pattern – Chapter 9
Section 11.1 Class Variables and Methods
Chapter 19: Interfaces and Components
Presentation transcript:

K. Stirewalt CSE 335: Software Design Synthetic OO Design Concepts & Reuse Lecture 5: Mixins and reusable strategies Topics: – More on the use of mixins – Example of refactoring to tame complexity – Reusable strategies and template-method pattern “One of the main characteristics of a computer science mentality is the ability to jump very quickly between levels of abstraction, almost unconsciously.” -- D. E. Knuth.

K. Stirewalt CSE 335: Software Design Outline of course topics Foundations of OO design Synthetic concepts: OO primitives in combination to produce design assets of various kinds Software architecture and larger design issues Software process issues

K. Stirewalt CSE 335: Software Design Outline of course topics Foundations of OO design Synthetic concepts: OO primitives in combination to produce design assets of various kinds Program families, program fragments, and abstract classes 1.Heterogeneous containers 2.Composite structures Separation of concerns 3.Separating/encapsulating cross-cutting operations [Visitor pattern] 4.Mixin classes 5.Reusable strategies and object-oriented frameworks Exam 1 Reusable collaborations Software architecture and larger design issues Software process issues

K. Stirewalt CSE 335: Software Design Where are we? Foundations of OO design Synthetic concepts: OO primitives in combination to produce reusable design assets Program families, program fragments, and abstract classes 1.Heterogeneous containers 2.Composite structures Separation of concerns 3.Separating/encapsulating cross-cutting operations [Visitor pattern] 4.Mixin classes 5.Reusable strategies and object-oriented frameworks Exam 1 Reusable collaborations Software architecture and larger design issues Software process issues

K. Stirewalt CSE 335: Software Design Recall: Program families and fragments XX X X Program fragments: retained; refined to produce new fragments and programs defer implementation/design decisions to fragments or programs “down the tree”. abstract operations specify “what”, not “how”

K. Stirewalt CSE 335: Software Design Example: Document editor Allows user to view and or edit documents of various types Different “kinds” of documents: –Plain text vs. rich text (with embedded fonts) –Shared documents vs. non-shared documents Some users may edit, others may only browse Need to protect access when multiple users are editing Problem: Procedure to open/manipulate a document varies among different document types

K. Stirewalt CSE 335: Software Design Example: Document class class Document { public: bool Open( const string& ); void Close(); void ReadLine( unsigned ); void AppendLine( unsigned, const string& ); void ReplaceLine( unsigned, const string& ); void View( unsigned, unsigned, Display* );... protected: FILE*f; }; bool Document::Open( const string& name ) { if((f = fopen(name, “r+”))==0) return false; return true; } void Document::Close() { fclose(f); }

K. Stirewalt CSE 335: Software Design Example: Adding rich text class Document {... protected: FILE*f; vector fonts; }; bool Document::Open( const string& name ) { if((f = fopen(name, “r+”))==0) return false; if (f && isRichTextFile(name)) { string fontFileName( name + “Fonts” ); FILE* fontfile; if((fontfile=fopen(fontFileName,...))==0) return false; // load contents into fonts fclose(fontfile); return true; }

K. Stirewalt CSE 335: Software Design Example: Adding sharing support class Document {... bool Open( const string& ); void Close();... protected: FILE*f; vector fonts; FILE*lockFile; };

K. Stirewalt CSE 335: Software Design Example: Document class bool Document::Open( const string& name ) { stringlockName(“.lock” + name); if (isSharedFile(name) && testAndSet(lockFile,lockName)) return false; if((f = fopen(name, “r+”))==0) return false; if (f && isRichTextFile(name)) { string fontFileName( name + “Fonts” ); FILE* fontfile; if((fontfile=fopen(fontFileName,...))==0) return false; // load contents into fonts fclose(fontfile); } void Document::Close() { fclose(f); if (isSharedFile(name)) { unlink(lockFile); } return true; }

K. Stirewalt CSE 335: Software Design Problems with this solution Code quickly getting very complex –Code for open has lots of “case logic” if (isSharedFile(name)), if (isRichTextFile(name)) –Cases not even localized lock file created at beginning of open method must be deleted at end of close method Document class becoming a “kitchen sink” with everything needed for any kind of document

K. Stirewalt CSE 335: Software Design Question Can you think of a way to redesign this class to tame this escalating complexity?

K. Stirewalt CSE 335: Software Design Candidate solution Develop a Document class hierarchy –Document becomes the base class –Each derived class adds a feature, such as rich text or support for sharing Sounds similar to how we developed the Employee–Manager hierarchy

K. Stirewalt CSE 335: Software Design Hierarchy of Document classes Document f : FILE Open() : Bool; Close() : Bool ReadLine( unsigned ) : void... RichDocument fonts : vector ; Open() : Bool SharedRichDocument lockFile : FILE Open() : Bool

K. Stirewalt CSE 335: Software Design Example: Adding rich text class RichDocument : public Document { bool Open(const string&); protected: vector fonts; }; bool RichTextDocument::Open( const string& name ) { if(!Document::Open(name)) return false; if (f && isRichTextFile(name)) { string fontFileName( name + “Fonts” ); FILE* fontfile; if((fontfile=fopen(fontFileName,...))==0) return false; // load contents into fonts fclose(fontfile); } return true; }

K. Stirewalt CSE 335: Software Design Class SharedRichTextDocument class SharedRichDocument : public RichTextDocument { public: bool Open( const string& ); void Close(); protected: FILE* lockfile; }; bool SharedRichDocument::Open( const string& name ) { stringlockName(“.lock” + name); if (isSharedFile(name) && testAndSet(lockName)) return false; return RichTextDocument::Open(name); } void SharedRichDocument::Close() { RichTextDocument::Close(); if (isSharedFile(name)) { unlink(lockFile); }

K. Stirewalt CSE 335: Software Design Question Can you spot any problems with this solution? Hints: –What if client wants to open a shared document that is not a rich-text document? –How must a client create a Document object of the proper type?

K. Stirewalt CSE 335: Software Design Problems w/ candidate solution Hierarchy itself complex because of the independent variation of features –Sharing vs. non-sharing orthogonal to rich vs. plain text –Do we need a new derived class for each possible combination –Will this scale? Pushes complexity out to the client: –Client needs to distinguish what “kind” of file to create so that it can decide which derived class to instantiate –What happens when we wish to support new kinds of files with new characteristics?

K. Stirewalt CSE 335: Software Design Question Can you spot any problems with this solution? Hints: –What if client wants to open a shared document that is not a rich-text document? –How must a client create a Document object of the proper type?

K. Stirewalt CSE 335: Software Design Solution idea “Stuff that is added” in each derived class has few dependencies on its base Sort of like a mixin class (e.g., RCObject) that is mixed in “in the middle of” rather than “at the top of” the class hierarchy Mixin classes of this sort can be defined in C++ using a combination of inheritance, polymorphism, and templates Allows management of independent variation of features

K. Stirewalt CSE 335: Software Design Solution using mixins template class RichDoc : public DOCUMENT_BASE { public: bool Open(const string&); }; template class SharedDoc : public DOCUMENT_BASE { public: bool Open(const string&); void Close(); };

K. Stirewalt CSE 335: Software Design Solution using mixins (cont) Now, we can support the following combinations: –Document –SharedDoc –SharedDoc > Example use: SharedDoc * myDoc; if (myDoc.Open(“foo.doc”)) {... myDoc.Close(); }

K. Stirewalt CSE 335: Software Design Exercise Write the code for the methods SharedDoc::Open and SharedDoc::Close

K. Stirewalt CSE 335: Software Design Question Can you spot any problems with this solution? Hints: –What if client wants to open a shared document that is not a rich-text document? –How must a client create a Document object of the proper type?