Cheng, CSE8701CSE870: Advanced Software Engineering (Frameworks, Part 2)RRRMore Frameworks• Acknowledgements:– K. Stirewalt– R. Johnson, B. Foote– Johnson, Fayad, SchmidtCSE870: Advanced Software Engineering (Frameworks, Part 2)RRROverview• Review of object-oriented programming (OOP) principles. • Intro to OO frameworks: o Key characteristics. o Uses. o Black-box vs. white-box frameworks. • Example study: Animations in thesubArctic UI toolkit. CSE870: Advanced Software Engineering (Frameworks, Part 2)RRRRecap on OOP• Key features that differentiate OOP from traditional block-structured languages: – Polymorphism: a late-binding feature, whereby a procedure is dynamically bound to a message request. – Inheritance: allows operations to be defined in one (parent) class and then overridden in another (child) class. • Inheritance and polymorphism together are the principle tools of OO frameworks.Cheng, CSE8702CSE870: Advanced Software Engineering (Frameworks, Part 2)RRRInheritance and polymorphism• Subclasses provide different methods for same operation. • Benefit: Enables decoupling of cooperating classes. –Clients need not know how an operation is implemented. –Thus, designs are portable and extensible. –Code can be reused. • Two cases: 1. Superclass provides a method for the operation. • we say the subclass overrides this method. • subclass method may explicitly invoke superclassmethod. 2. Superclass provides no method for the operation. • we say the operation is abstract in the superclass. CSE870: Advanced Software Engineering (Frameworks, Part 2)RRRProtocol • Operations performed on objects by ``sending them messages''. • Specification of an object given by its message protocol: – Set of messages that can be sent to it; – Includes type of arguments of each message. • Objects with identical protocols are interchangeable. • Interface between objects defined by protocols they expect each other to understand. • In most languages, protocol is bound to an object's class1.CSE870: Advanced Software Engineering (Frameworks, Part 2)RRRAbstract classes • Defn: class that cannot have any instances. • Only subclasses can have instances. • How to specify that a class is abstract: – C++: Implicit; abstract class has pure virtual functions. – Java: • Class can be explicitly declared abstract, or • Abstract operations can be grouped into an interface. • Used to define standard protocols.Cheng, CSE8703CSE870: Advanced Software Engineering (Frameworks, Part 2)RRRUse of Abstract Class to Represent a ProtocolCSE870: Advanced Software Engineering (Frameworks, Part 2)RRRAbstract Operations and Design Coupling• Imagine:a tool that places figures on a grid. – Example: gridding of program icons in a window manager. – Example: placement of button figures in a panel. • Grid-management code allocates figures to grid positions, avoiding collisions and possibly implementing a fill policy. • Code should not be concerned with how to draw a figure. • Question: How do you separate grid management from the drawing of figures? CSE870: Advanced Software Engineering (Frameworks, Part 2)RRRExample Decoupling using abstract operationsCheng, CSE8704CSE870: Advanced Software Engineering (Frameworks, Part 2)RRRExample: Use of these classes#include "Square.h"#include "Triangle.h"#include "Circle.h"#include "Grid.h"...Grid myGrid;...myGrid.AddFigure( new Square );myGrid.AddFigure( new Triangle );myGrid.AddFigure( new Circle );myGrid.Draw();CSE870: Advanced Software Engineering (Frameworks, Part 2)RRRExample: continuedclass Figure : public WindowComponent {public:virtual void Draw() = 0; // pure virtual function!}; class Grid : public WindowComponent {public:void AddFigure( Figure* );void Draw() {for( int i=0; i < 3; ++i ) {figures[i].Draw();}private:Figure* figures[3];};CSE870: Advanced Software Engineering (Frameworks, Part 2)RRRPlug Compatibility• If several classes define same protocol, then objects in those classes are plug compatible. • Thus complex objects can be created by plugging together a set of compatible components. • Style of programming called building tool kits.Cheng, CSE8705CSE870: Advanced Software Engineering (Frameworks, Part 2)RRRIntro to OO FrameworksCSE870: Advanced Software Engineering (Frameworks, Part 2)RRRFramework• Support reuse of detailed designs• An integrated set of components:– Collaborate to provide reusable architecture for– Family of related applicationsCSE870: Advanced Software Engineering (Frameworks, Part 2)RRRFrameworks1. Frameworks are semi-complete applications• Complete applications are developed by inheriting from, and• Instantiating parameterized framework components2. Frameworks provide domain-specific functionality• Ex.: business, telecommunication, dbases, distributed, OS kernels3. Frameworks exhibit inversion of control at run-time• Framework determines which objects and methods to invoke in response to eventsCheng, CSE8706CSE870: Advanced Software Engineering (Frameworks, Part 2)RRRClass Libraries vs Frameworks vs Patterns• Definition: – Class Libraries:• Self-contained,• Pluggable ADTs– Frameworks:• Reusable, semi-complete applications– Patterns:• Problem, solution, contextApplicationSpecificLogicNetworkingMathDbaseADTsUIEventLoopApplicationSpecific LogicMathADTsEventLoopUINetworkingDbaseInvokesInvokesCall BacksClass Library ArchitectureFramework ArchitectureCSE870: Advanced Software Engineering (Frameworks, Part 2)RRRCharacteristics of Frameworks• Often: o User-defined methods invoked by the framework code itself. o Framework plays the role of ``main program''. • This inversion of control allows frameworks to serve as extensible code skeletons. • User-supplied methods tailor generic framework algorithms for a specific application. CSE870: Advanced Software Engineering (Frameworks, Part 2)RRRObject-Oriented Frameworks• A.k.a: Object-oriented abstract design. • Consists of: o Abstract class for each major component; o Interfaces between components defined in terms of sets of messages. o Usually a library of subclasses that can be used as components in the design. • Many well-known examples: o All modern UI toolkits (e.g., Java AWT, subArctic, MFC). o Distributed computing toolkits (e.g., ACE).Cheng, CSE8707CSE870: Advanced Software Engineering (Frameworks, Part 2)RRRExample: Java AWT Framework (abstracted)CSE870: Advanced Software
View Full Document