1 Kyung Hee University Diagram Editor : Implementation View Spring 2001.

Slides:



Advertisements
Similar presentations
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
Advertisements

CSI 3120, Exception handling, page 1 Exception and Event Handling Credits Robert W. Sebesta, Concepts of Programming Languages, 8 th ed., 2007 Dr. Nathalie.
Object Oriented Programming with Java (150704).   Applet  AWT (Abstract Window Toolkit)  Japplet  Swing Types of Applet.
Object-Oriented Analysis and Design
2 Object-Oriented Analysis and Design with the Unified Process Objectives  Explain how statecharts can be used to describe system behaviors  Use statecharts.
Introduction To System Analysis and Design
Object-Oriented PHP (1)
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Essentials of interaction diagrams Lecture Outline Collaborations Interaction on collaboration diagrams Sequence diagrams Messages from an object.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Chapter 10 Classes Continued
C++ fundamentals.
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
OOP Languages: Java vs C++
Software Engineering 8. System Models.
Introduction To System Analysis and design
Object Oriented Software Development
Programming Languages and Paradigms Object-Oriented Programming.
Systems Analysis and Design in a Changing World, Fifth Edition
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 7 Slide 1 System models l Abstract descriptions of systems whose requirements are being.
Chapter 4 System Models A description of the various models that can be used to specify software systems.
System models Abstract descriptions of systems whose requirements are being analysed Abstract descriptions of systems whose requirements are being analysed.
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Chapter 7 System models.
System models l Abstract descriptions of systems whose requirements are being analysed.
Modified by Juan M. Gomez Software Engineering, 6th edition. Chapter 7 Slide 1 Chapter 7 System Models.
Systems Analysis and Design in a Changing World, 3rd Edition
UML Class Diagram Trisha Cummings. What we will be covering What is a Class Diagram? Essential Elements of a UML Class Diagram UML Packages Logical Distribution.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
1 Kyung Hee University Diagram Editor : Design View Spring 2001.
1 Kyung Hee University Statecharts Spring Kyung Hee University Specifying Objects’ Behaviour  Interaction diagrams show message-passing behaviour.
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
Object Oriented Programming.  Interface  Event Handling.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Review Class Inheritance, Abstract, Interfaces, Polymorphism, GUI (MVC)
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Designing Classes CS239 – Jan 26, Key points from yesterday’s lab  Enumerated types are abstract data types that define a set of values.  They.
1 Kyung Hee University Modeling with Objects Spring 2001.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
M1G Introduction to Programming 2 5. Completing the program.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
Interfaces About Interfaces Interfaces and abstract classes provide more structured way to separate interface from implementation
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Diagram Editor : Use Case VIew
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
Kyung Hee University Class Diagramming Notation OOSD 담당조교 석사과정 이정환.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
1 Kyung Hee University Interaction Diagrams Spring 2001.
CSCI-383 Object-Oriented Programming & Design Lecture 17.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Modern Programming Tools And Techniques-I
Activities and Intents
CMSC 202 Exceptions.
Presentation transcript:

1 Kyung Hee University Diagram Editor : Implementation View Spring 2001

2 Kyung Hee University Diagram Editor: Implementation Implementation of a design is often bound up with various technology choices. For a system which has to maintain a large amount of data, a suitable database backend will often be chosen. For a distributed application, suitable communication protocols will be considered. The diagram editor is representative of a large class of interactive, single-user applications with a windows-based graphical user interface and user interactions supplied by means of devices such as a mouse and a keyboard. The design so far has considered the specific functionality of the diagram editor, but not the details of the interaction and display of information. Because this type of application is so common, and because the user-interface code is essentially the same for all such applications, frameworks have evolved which provide a standard architecture for such applications.

3 Kyung Hee University Frameworks  In this type of application, a framework will: manage windows, and provide standard user-interface widgets detect user input (from mouse, keyboard or widget) provide library functions for producing output  The term framework is used because: this code “surrounds” the application-specific code it provides a skeletal but complete application which the framework user can extend and specialize

4 Kyung Hee University What a framework does  The framework: Shields the programmer from details of low-level APIs, thus making application development easier Provides generic functionality that can be used in many applications

5 Kyung Hee University Hotspots  Object-oriented frameworks usually provide “hotspots”: classes in the framework that the framework user can specialize to provide application-specific functionality.

6 Kyung Hee University Hotspots (cont’d) 1.The framework calls the functions of the hotspot class. Default versions of these are provided by the framework. 2.The user defines an application-specific specialization of the hotspot class, and overrides the necessary functions. 3.By using late binding the framework then executes the user’s code, not the default code.  This mechanism is often known as inversion of control. A framework provides reusable code which calls the programmers code. This is the opposite of what happens with traditional libraries.

7 Kyung Hee University Overriding framework operations  One way of using a framework is to override operations that are provided in the hotspot classes.

8 Kyung Hee University Overriding framework operations (cont’d)  The framework detects a mouse move, and sends a mouseMove message to the hotspot class.  The framework provides a default implementation of this operation, which probably does nothing.  In an application, this operation can be overridden to implement specific functionality.

9 Kyung Hee University Overriding callback operations  Sometimes the interaction involved is a bit more complex. The framework detects a situation in which the display could be altered, and sends a redisplay message to the hotspot class.

10 Kyung Hee University Overriding callback operations  The framework detects a situation in which the display could be altered, and sends a redisplay message to the hotspot class.  The framework provides a default implementation of this operation, which calls an auxiliary function displayConten t. Perhaps redisplay draws windows and scroll bars, but displayContent draws application data.  In an application, the displayContent operation can be overridden to implement specific functionality.

11 Kyung Hee University Example: Java applets  The implementation of the diagram editor as a Java applet uses two “hotspots” provided by the Java API.  The Applet class in the Java API provides the ability to run the diagram editor in a Web page, for example.  The Canvas class enables the display of the current diagram, and also traps the user-generated events such as mouse moves.

12 Kyung Hee University Handling user input  When the user moves the mouse over the diagram editor, this event is detected by the Java run-time system and translated into a call to the method ‘mouseMove’, which is defined in the canvas class.  For example, the Java 1.0 run-time system ensures that the message MouseMove() is sent to the canvas.  If the DiagramEditor class overrides this method, it will be able to send the appropriate message on to the current tool object:

13 Kyung Hee University Handling output  The implementation of the diagram editor will follow a fundamental strategy of keeping display code separate from application code.  Display of the elements on the current diagram will be performed in response to the Paint method of the canvas class.  This message can either be sent by the framework (for example, if the applet is uncovered and needs to be refreshed) or by the application (for example, if the user updates the diagram in any way).

14 Kyung Hee University Handling output (cont’d)

15 Kyung Hee University Redrawing the diagram  The paint method simply redraws everything, including: The diagram, which draws Every element The current tool (to draw any interaction-specific stuff such as the faint images displayed when an element is being created). Parameter ‘g’ on the messages is a reference to a graphics context in which drawing can take place.

16 Kyung Hee University Implementation of Classes  There is a direct correspondence between the basic UML notation for classes and object-oriented code.  As this illustration suggests: UML classes are represented by classes in Java or C++, and abstract classes by abstract classes. Attributes are represented by private data members. Operations are represented by public methods.  The implementation of the class has to be specific about the types of variables and functions, which are often omitted in UML.

17 Kyung Hee University Implementation of Generalization  The UML relationship of generalization should be implemented using inheritance in Java or C++.  Generalization has two important properties in UML, both of which are preserved by this implementation. Substitutability Instances of subclasses should be usable wherever an instance of a superclass is expected or specified. Inheritance Data members and methods defined in a superclass are inherited and become in effect members of the subclass.

18 Kyung Hee University Implementation of Links and Associations  Java, in common with most other programming languages, provides no direct support for associations. One common strategy strategy is to use references to implement associations.  Objects are connected at run-time by links which enable objects to send messages to each other: holding a reference to another object provides this functionality.  A complication with this implementation is that links are bidirectional: messages can be passed along a link in either direction. References, on the other hand, are uni-directional.  To provide the full functionality of a link, two references would be required, one pointing in either direction.

19 Kyung Hee University Implementation of Links and Associations  To avoid the additional overheads and complexity involved in supporting inverse references of this type, associations are often implemented in one direction only.

20 Kyung Hee University Unidirectional Implementation  In practice, many associations are only used in one direction. For example, a diagram object sends messages to elements, but no messages flow in the other direction.  In this case, the implementation can be simplified by only providing a pointer in the direction of use.  This implementation decision can be documented by including an arrowhead on the association.

21 Kyung Hee University Unidirectional Implementation (cont’d)  Arrowheads can be added to associations to show the intended direction of implementation, or navigation. The diagram class simply stores a vector of references to elements, thus supporting the “many” multiplicity of the association.

22 Kyung Hee University Unidirectional Implementation (cont’d)  A simple implementation of this unidirectional association public class Diagram { private Vector elements = new Vector(16) public void add (Element e) { elements.addElement (e); }

23 Kyung Hee University Implementing Multiplicity Constraints  If the multiplicity of an association is “one” rather than “many”, it can be implemented by a single reference. If the multiplicity is “exactly one”, however, care must be taken to ensure that the reference is always non-null.

24 Kyung Hee University Implementing Multiplicity Constraints (cont’d) public abstract class Tool { Diagram diagram ; Tool(Diagram d) { if ( d == null ) { // throw NullDiagramError } diagram = d ; }

25 Kyung Hee University Implementation of Statecharts  A statechart specifies, for each instance of a class, the possible states it can be in, how it switches from one state to another, and in some cases how an object’s behaviour depends on its current state.  A simple way of implementing the states of an object is with an enumeration type whose values represent the possible states. Here for example is the definition of the possible states of the selection tool:

26 Kyung Hee University Implementation of Statecharts (cont’d) public class SelectionTool extends Tool { final static int Locating = 0 ; final static int Moving = 1 ; final static int Resizing = 2 ; final static int Error = 3 ; int state ; } The intention behind this is that at any given instant, the value stored in state will specify the current state of the tool.

27 Kyung Hee University Implementation of Statecharts (cont’d) public abstract class CreationTool extends Tool { final static int LocatingStart = 0; final static int LocatingStop = 1; int state; CreationTool (Diagram d) { super(d); state = LocatingStart; } … } The creation tool hierarchy

28 Kyung Hee University Implementation of Statecharts (cont’d) public void operation () { switch (state) { case LocatingStart: // Specific actions for locating start state break; case LocatingStop: // Specific actions for locating stop state break; }

29 Kyung Hee University Implementation of Statecharts (cont’d)  public void release () { switch (state) { case LocatingStart: break; case LocatingStop: Element e = newElement (start, Current); Diagram.add(e); state = LocatingStart; break; }

30 Kyung Hee University Implementation of Statecharts (cont’d) public class RectangleTool extends CreationTool { Element (Point start, Point stop) { … } void drawElement (Graphics g){ … } }

31 Kyung Hee University Implementation of Statecharts (cont’d)  Selection tool class public void press () switch (state) { case Locating: if (findControl (current)) { state = Resizing; } else if (diagram.find(current) != null) { state = Moving ; } else { state = off; Case Moving: break; Case Resizing: break; Case error:break; }

32 Kyung Hee University Implementation of events  Events in a statechart often simply correspond to calls of operations in the class. In some cases, the implementation of an operation depends on the current state of an object.  This can be made very clear by structuring operations as a switch statement with different cases for the different states.

33 Kyung Hee University Implementation of events (cont’d) void move(int x, int y) { switch (state) { case Locating: break ; case Moving: Enumeration enum = selected.elements() ; // Move each element in turn break ; case Resizing: resizing.moveCP(x-lastPoint.x, y-lastPoint.y) ; break ; case Error: break ; } lastPoint = new Point(x, y) ; }

34 Kyung Hee University Tool management  The design states that there is only one tool active in the editor at any given time. When the user requests the creation of a new tool, something like the following must happen:  We also need to do this whenever the current diagram is changed, to ensure that the current tool is always active on the current diagram. Otherwise, strange effects might ensue.

35 Kyung Hee University Document/View architecture  An alternative framework to Java applets is provided by Microsoft’s diagram/view architecture. The name is derived from the two most significant hotspot classes in the framework.

36 Kyung Hee University Document/View architecture (cont’d)  Documents represent sensible units of data, such as a file, or in this case a diagram.  Views present the information in a document graphically in a window.

37 Kyung Hee University Document/View (2)  The diagram editor application can be integrated into the document/view framework as follows:  The application class is provided by the framework, but can be generated automatically by a Microsoft tool. It contains no application-specific code.