Cheng, CSE870. More Frameworks. Overview. Recap on OOP. Acknowledgements:

Similar documents
OO Frameworks. Introduction. Using Frameworks

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

GUI Software Architecture

The AWT Event Model 9

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

ITI Introduction to Computing II

CSSE 220. Event Based Programming. Check out EventBasedProgramming from SVN

8. Polymorphism and Inheritance

Windows and Events. created originally by Brian Bailey

Java Object Oriented Design. CSC207 Fall 2014

CSE 70 Final Exam Fall 2009

Object Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance

ITI Introduction to Computing II

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Inheritance and Substitution גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

UCLA PIC 20A Java Programming

TYPES OF INTERACTORS Prasun Dewan Department of Computer Science University of North Carolina at Chapel Hill

Get Unique study materials from

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OVERRIDING. 7/11/2015 Budditha Hettige 82

Inheritance. Transitivity

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes

Chapter 10 Classes Continued. Fundamentals of Java

Chapter 5 Object-Oriented Programming

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Inheritance and Polymorphism

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

Object-Oriented Concepts and Design Principles

Data Abstraction. Hwansoo Han

Topics in Object-Oriented Design Patterns

8.1 Inheritance. 8.1 Class Diagram for Words. 8.1 Words.java. 8.1 Book.java 1/24/14

Solution register itself

ECE 122. Engineering Problem Solving with Java

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

Inheritance and Polymorphism

7. Program Frameworks

Inheritance and Polymorphism

G Programming Languages - Fall 2012

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology:

CSE 452: Programming Languages. Previous Lecture. From ADTs to OOP. Data Abstraction and Object-Orientation

GUI in Java TalentHome Solutions

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

C++ Important Questions with Answers

GUI Event Handlers (Part I)

What is Inheritance?

IT101. Inheritance, Encapsulation, Polymorphism and Constructors

Object-Oriented Design

CPS 506 Comparative Programming Languages. Programming Language

UML & OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 3 08/30/2011

Class Hierarchy and Interfaces. David Greenstein Monta Vista High School

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

Lecture Notes on Programming Languages

CMSC 132: Object-Oriented Programming II

UI Software Organization

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

MARS AREA SCHOOL DISTRICT Curriculum TECHNOLOGY EDUCATION

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming

PESIT Bangalore South Campus

SubArctic UI Toolkit User's Manual St. Paul Release (Beta version 0.8e) Table of Contents

CS 11 java track: lecture 3

Chapter 5. Inheritance

ECE 462 Object-Oriented Programming using C++ and Java. Key Inputs in Java Games

G Programming Languages Spring 2010 Lecture 9. Robert Grimm, New York University

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.

Advanced Java Programming (17625) Event Handling. 20 Marks

COP 3330 Final Exam Review

SDC Design patterns GoF

CS11 Java. Fall Lecture 4

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

CS 251 Intermediate Programming Inheritance

CSCE3193: Programming Paradigms

CS111: PROGRAMMING LANGUAGE II

Inheritance and Substitution (Budd chapter 8, 10)

Comp-304 : Object-Oriented Design What does it mean to be Object Oriented?

Lecture 18 CSE11 Fall 2013 Inheritance

Chapter 1: Object-Oriented Programming Using C++

CHAPTER 9 DESIGN ENGINEERING. Overview

What are the characteristics of Object Oriented programming language?

GUI Components: Part 1

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

Review. Designing Interactive Systems II. Introduction. Web 2.0 in keywords GWT Cappuccino HTML5. Cross platform GUI Toolkit

Designing Interactive Systems II

Basic Object-Orientation

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.

Inheritance, Polymorphism and the Object Memory Model

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

CSE 307: Principles of Programming Languages

Information System Design (IT60105)

Transcription:

More Frameworks Acknowledgements: K. Stirewalt. Johnson, B. Foote Johnson, Fayad, Schmidt Overview eview 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 the subarctic UI toolkit. ecap 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. 1

Inheritance 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 superclass method. 2. Superclass provides no method for the operation. we say the operation is abstract in the superclass. Protocol 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 class 1. Abstract 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. 2

Use of Abstract Class to epresent a Protocol Abstract 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? Example Decoupling using abstract operations 3

Example: 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(); Example: continued class 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]; }; Plug 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. 4

Intro to OO Frameworks Framework Support reuse of detailed designs An integrated set of components: Collaborate to provide reusable architecture for Family of related applications Frameworks 1. Frameworks are semi-complete applications Complete applications are developed by inheriting from, and Instantiating parameterized framework components 2. Frameworks provide domain-specific functionality Ex.: business, telecommunication, dbases, distributed, OS kernels 3. Frameworks exhibit inversion of control at run-time Framework determines which objects and methods to invoke in response to events 5

Class Libraries vs Frameworks vs Patterns Application Specific Networking Logic Invokes Math ADTs Event Loop Math ADTs UI Application Specific Logic Dbase Class Library Architecture Invokes Networking Call Backs Dbase UI Framework Architecture Event Loop Definition: Class Libraries: Self-contained, Pluggable ADTs Frameworks: eusable, semicomplete applications Patterns: Problem, solution, context Characteristics 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. Object-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). 6

Example: Java AWT Framework (elided) Whitebox Frameworks Program skeleton: Subclasses are the additions to skeleton Implications: Framework implementation must be understood to use Every application requires the creation of many new subclasses Can be difficult to learn: Need to need how it was constructed (hierarchical structure) State of each instance is implicitly available to all methods in framework (i.e., similar to global vars) Example: Event handling in Java AWT 1.02 and before Events are propagated from components to their containers until such time as the event is serviced. Every component has the operation: public boolean handleevent( Event event ); To handle an event, simply override this operation with a method. Note the return type (boolean) that is used by the framework to decide whether or not the event was handled by the component. If not handled, then the event is propagated to the component's container. 7

Blackbox Frameworks Customize framework by supplying with set of components that provide application-specific behavior Implications: Each component required to understand a particular protocol All or most components from component library Interface between components defined by protocol Need to only understand external interface of components Less flexible Info passed to application components must be explicitly passed. Example: Event handling in Java AWT 1.0 and 1.1 In the 1.0 version of Java AWT, event handling was implemented using inheritance. In 1.1, this model was replaced with a delegation-based model; i.e., one that is built around protocols rather than implementation sharing. Event handling (AWT 1.1) Events are first-class objects. o There is a class Event. o Subclasses identify different kinds of events. Components fire events. Other objects can listen for/act upon these events. Interested objects register themselves as a Listener with the component that fires the event. 8

AWTEvent hierarchy Event routing Lots of different kinds of events. o Different events carry different types of information. o E.g., ActionEvent carries a command, TextEvent carries a string being edited. Components fire these events. E.g., Button fires an ActionEvent. E.g., TextArea fires a TextEvent. All components fire WindowEvents. When fired, events are routed to special Listener objects Listeners A listener is an object to which AWTEvents can be routed by components. Different types of listeners. o One for each subclass of AWTEvent. o E.g., ActionListener, ComponentListener, WindowListener. o A listener class is abstract: o Operation names only; no attributes or methods. o Declared as an interface in Java. 9

Example: An action-event listener class ButtonListener implements ActionListener { public void actionperformed(actionevent event) { System.out.println("Button pressed!!!"); } } public class ActionExample extends Applet { public void init() { Button button = new Button("Push me"); button.addactionlistener( new ButtonListener()); } add(button); } Example: A mouse-event listener class ButtonMouseListener implements MouseListener { public void mouseentered(mouseevent event) { System.out.println("Mouse entered button!"); }; } public void mouseexited(mouseevent event) { System.out.println("Mouse exited button!"); }; public void mousepressed(mouseevent event) public void mouseclicked(mouseevent event) {} public void mouseeleased(mouseevent event) {} Design schema for event routing oute events of class E from graphical component C to object O: 1. Design O to be an E-listener. Class of O must implement the E-listener interface. The corresponding methods must service the event. 2. Add O to C's set of listeners. Pseudo-code: C.addEListener(O); 10

Example OO Framework: Animations in the subarctic UI Toolkit SubArctic and animation SubArctic is a Java-based UI toolkit developed at Georgia Tech and Carnegie Mellon. Powerful support for animations: o High-level model for describing time-based events in a UI. o Allows traditional image (i.e., page-flipping) animations. o Also allows objects to smoothly move about screen, modify color over time, etc. Implemented as an OO framework. Abstract UML of the framework 11

Data Dictionary Interactor: interface defines the API that all objects appearing on the screen and/or accepting input must provide. Defines all basic operations of interactive objects Base_parent_interactor: Base class for objects that support (arbitrary) children. Provides default implementation for all methods defined by interactor interface and supports routines Animatable: Input protocol interface for specifying that an object is animatable. Each interactor that expects to receive animation input must implement animatable input protocol. Anim_mover_container: A container class to move a collection of objects under control of an animation transition. Callback_object: Interface for objects that receive callback from interactors.callbacks are entities which are notified when significant user actions (such as a button press or a menu selection) occur. Implemented as objects in subarctic Transition: primary abstraction for describing how animations are to proceed in subarctic. Combo of animations logical path, optional pacing function assoc. with path (does object move uniformly among values of path), animations time interval (how long does it take and when does it start) Time_interval: first part of trajectory (absolute or relative form) Trajectory: specifies mapping from time to a set of values (e.g., screen space) Pacer: allow non-linear behavior for mapping SubArctic animations Animation = complex collaboration among multiple objects interactor is the object being animated Some classes/interfaces support customized animations For example: trajectory used for positional path variation (straight line, running-start, smooth curve, etc.) pacer used for non-linear time variation Others provide communication hooks. Callback_object receives notifications at the beginning of the animation Application Construction Environments (Toolkits) Defn: Collection of high-level tools that allow a user to interact with an OO framework to configure and construct new applications [Johnson:joop88]. Key observation: Easier to build a tool to specialize classes with well-defined interfaces than to build a general-purpose code generator 12

Influence of OO Frameworks 13