Satisfying Open/Closed Principle

Slides:



Advertisements
Similar presentations
Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not.
Advertisements

R R R CSE870: Advanced Software Engineering: Frameworks (Cheng, Sp2003)1 Frameworks A Brief Introduction.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Adapters Presented By Zachary Dea. Definition A pattern found in class diagrams in which you are able to reuse an ‘adaptee’ class by providing a class,
Software Issues Derived from Dr. Fawcett’s Slides Phil Pratt-Szeliga Fall 2009.
Reuse Activities Selecting Design Patterns and Components
UNIT-V The MVC architecture and Struts Framework.
1 Dept. of Computer Science & Engineering, York University, Toronto CSE3311 Software Design Adapter Pattern Façade pattern.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
Ceg860 (Prasad)L6MR1 Modularity Extendibility Reusability.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Object Oriented Software Development
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Object Oriented Programming Some Interesting Genes.
Engineered for Tomorrow Unit:8-Idioms Engineered for Tomorrow sharmila V Dept of CSE.
A Method for Improving Code Reuse System Prasanthi.S.
Software Reuse. Objectives l To explain the benefits of software reuse and some reuse problems l To discuss several different ways to implement software.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
CSE687 - Object Oriented Design class notes Survey of the C++ Programming Language Jim Fawcett Spring 2005.
Design Patterns: MORE Examples
Abstract Factory Pattern
Factory Method Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Dependency Analysis Use Cases
Objects First with Java A Practical Introduction using BlueJ
MPCS – Advanced java Programming
Jim Fawcett CSE791 – Distributed Objects Spring 2001
CSE687 - Object Oriented Design class notes Survey of the C++ Programming Language Jim Fawcett Spring 2004.
Behavioral Design Patterns
Chapter 9 - Programming to Interfaces
Enterprise Computing Collaboration System Example
Processes The most important processes used in Web-based systems and their internal organization.
CHAPTER 3 Architectures for Distributed Systems
Template Policies and Traits By Example
Factory Method Pattern
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Dependency Analysis Use Cases
Abstract Factory Pattern
Intent (Thanks to Jim Fawcett for the slides)
Chapter 16 – Software Reuse
Object Oriented Programming
Objects First with Java A Practical Introduction using BlueJ
Adapter Pattern 1.
IFS410: Advanced Analysis and Design
lecture 08, OO Design Principle
Week 6 Object-Oriented Programming (2): Polymorphism
Software Architecture
Software Design Lecture : 12.
Software Design Lecture : 14.
An Introduction to Software Architecture
Objects First with Java A Practical Introduction using BlueJ
IntroductionToPHP Static vs. Dynamic websites
Structural Patterns: Adapter and Bridge
Lesson 5: More on Creational Patterns
Objects First with Java A Practical Introduction using BlueJ
Chapter 16 – Software Reuse
Dependency Inversion principle
Chapter 8 - Design Strategies
Template Policies and Traits By Example
Adapter Pattern Jim Fawcett
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
Message Passing Systems Version 2
C++ Object Oriented 1.
ONAP Architecture Principle Review
Adapter Pattern Jim Fawcett
Jim Fawcett CSE687 – Object Oriented Design Spring 2015
Message Passing Systems
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Chapter 10 – Component-Level Design
Presentation transcript:

Satisfying Open/Closed Principle Jim Fawcett CSE687 – Object Oriented Design Spring 2003

Statement of Principle Software entities (classes, modules, functions) should be open for extension, but closed for modification. Definitions Open: A component is open if it is available for extension: add data members and operations through inheritance. Create a new policy template argument for a class that accepts policies. Closed: A component is closed if it is available for use by other components but may not, itself, be changed, e.g., by putting it under configuration management, allowing read only access.

Application Domain vs. Solution Domain As designers, one of our goals should be to build programs with an Executive layer and a series of libraries of reusable code. The executive layer consists of an executive module and, perhaps, a few top level modules that are all application specific. This top layer supports all of the application requirements. The remainder of the design consists of reuseable components. The reuseable part are solution-side components that carry out basic and often needed operations. This ideal is hard to realize unless we can make the reuseable part extenible. Seldom do we have enough foresight to predict all the needs of the application. Application requirements change while we’re building.

Extensions and Binding If our efforts to build reusable components are successful, each new project will need to build less on the reusable side and can focus on meeting project requirements. That can only works if the reusable components can be extended. We almost always achieve extendability by providing for application design-time binding in our library design-time designs. Design for application-binding when doing library design.

How do Libraries provide Application Binding? Polymorphism Build hook classes that provide virtual functions that applications override to define application specific processing. Defind protocols that the library uses and application designers provide by overriding in a derivation of the protocol class. The library may provide derived classes to meet known requirements. Application designers add new derived classes driven by increasing knowledge about the requirements or requirements changes. Template policies and traits Build functions and classes parameterized by policy classes that allow application designers to extend by defining new policies, without changing any of the template class. Provide traits to make it easier for application designers to build policy classes.

Extending Functions Closed functions with template parameters can be extended by defining new compatible classes, used as template parameters. Example: trace class member template <typename T> trace& Add(const T& t) { std::ostringstream oss; oss << t; *this += ' '; *this += oss.str(); return *this; } The Add function accepts a reference to an unspecified type. If the type is convertible by an ostream then its string representation will be stored in the trace string-like object for later display.

Extending Functions If we develop a user defined type that can serialize its state to a stream: A vec3D converting its coordinates to a displayable string An html element object serializing to a tagged string Then this type can be used by trace::Add(const T &t) to save its string representation for a trace display. We could make trace effective for debugging a current project by providing serialization to string form for objects used in the implementation.

Extending Classes If the library designer supported extensions by providing: Protocol classes Hook classes Template policy parameters and traits then you simply design plug-in classes to tailor operation of the library. Even when the library does not provide these facilities, you often can extend existing concrete classes as we did for trace.

Graphics Editor Protocol class

Catalog Prog. Hook Class

codeDelimiter Template Policy Class The codeDelimiter class is a functor that defines all single-character tokens. An object of this class is used by toker to customize how tokens are collected: for parsing code for parsing XML documents

Deriving from Concrete Classes

Even this is not the End of the Story! The design patterns class covers about 30 patterns, some of which are designed to support extension of existing classes. The Adapter Pattern is typical of these. It provides a way to provide a specific required interface for a client from a class or classes that do not directly support the interface, but do provide a lot of the required functionality. Most of the patterns focus on ways a client can avoid binding to a concrete class.

Class Adapter Client Target Adaptee Request( ) SpecificRequest( ) (implementation) Adapter Request( ) SpecificRequest( )

End of Presentation