• 沒有找到結果。

belonging to different types to respond to method calls of methods of the same name,

N/A
N/A
Protected

Academic year: 2021

Share "belonging to different types to respond to method calls of methods of the same name, "

Copied!
8
0
0

加載中.... (立即查看全文)

全文

(1)

Chapter 5 Design and Implementation

5.1 The object oriented structure

In object-oriented programming theory, polymorphism is the ability of objects

belonging to different types to respond to method calls of methods of the same name,

each one according to an appropriate type-specific behavior. The programmer (and the

program) does not have to know the exact type of the object in advance, so this

behavior can be implemented at run time (this is called late binding or dynamic

binding).

The different objects involved only need to present a compatible interface to the

clients (the calling routines). That is, there must be public methods with the same

name and the same parameter sets in all the objects. In principle, the object types may

be unrelated, but since they share a common interface, they are often implemented as

subclasses of the same parent class. Though it is not required, it is understood that the

different methods will also produce similar results (for example, returning values of

the same type). [16]

For this benefit, we use the object oriented paradigm to design the Visualization

Metaphor Programming Paradigms. With the object oriented paradigm, the DIVINE

system can just use the same routine call to all the different VM designing by different

(2)

VM programmer. It will reduce the change of the system code in the future.

Figure 5-1 Inheritance architecture of Visualization Metaphor

Figure 5-1 shows the class diagram of the Visualization Metaphor Programming

Paradigms. The DIVINEVM class extends the OgreVMObject to be a 3D object,

extends the observer class to be an observer of Observer Pattern and implements the

abstract action method to interaction with the 3D user interface.

The ObjectVM, CompositeVM and RelationVM are extended from the

(3)

create the abstract class DIVINEVM to be the super class of the three VM classes.

In the future, maybe more different type VM would be defined, but have the

same attribute and method, so it can just extends from the DIVINEVM rather then

define the attribute and method itself.

5.2 The interaction of debugging objects and VM object

The Observer Pattern defines a one-to-many dependency between a subject

object and any number of observer objects so that when the subject object changes

state, all its observer objects are notified and updated automatically.

The following is class diagram and sequence diagram of an observer pattern:

Figure 5-2 The class diagram of an Observer Pattern.

(4)

Figure 5-3 The sequence diagram of an Observer Pattern.

In the Visualization Metaphor Programming Paradigms, we are using the

Observer Pattern to make the debugging object updating the changed data

automatically. The reason of why we use this pattern is it can automatically update the

changed date rather then the VM programmer should take care of the data changed in

the debugging object.

The debugging object extends the subject class to be a concretesubject. The VM

extends the observer class to be a concreteobserver. When the VM is chosen to be a

representation of a debugging object, the VM will be attach to the debugging object.

In the constructor of the VM, it will register the variable to the Mapping Engine.

When the debugging object data changed, the subject will notify the entire observer to

update. The Update method of each observer will be called to update the variable

which registers to the Mapping Engine.

(5)

aSubject

Data Changed

Notify()

aObjectVM

Update()

RenderEngine

draw()

draw()

Figure 5-4 The sequence diagram of the interaction of visualization metaphor

Figure 5-4 shows an interaction example of the VM and Observer Pattern. The

rendering engine calls the draw method of each visualization metaphor every frame to

repaint the 3D object. When the debugging information changed, the subject will

notify all of the observers that attach to it and call the Update method of the observer

to get the changed debugging information.

Therefore, while the rendering engine calls the draw method will get the new

data of the 3D object and repaint it. The VM programmer does not need to handle the

changed debugging information. It will automatically update by the observer design

pattern.

5.3 The composite object

In the separated visualization metaphor has the base type visualization

(6)

metaphor – ObjectVM, and the combinative of the base visualization - CompositeVM.

If the CompositeVM should define the presentation and behavior of each visualization

metaphor in it, it will lose the useful of the definition of the combinative visualization

metaphor. Hence, we use the Composite Pattern in the CompositeVM. The definition

of the Composite Pattern is described below.

Composite is an object (e.g. a shape) designed as a composition of one-or-more

similar objects (other kinds of shapes/geometries), all exhibiting similar functionality.

This is known as a "has-a" relationship between objects. The key concept is that you

can manipulate a single instance of the object just as you would a group of them. The

operations you can perform on all the composite objects often have a least common

denominator relationship. For example, when resizing a single shape to fill the screen,

surely you would expect/desire that resizing a group of shapes would have the same

effect.[16]

(7)

Figure 5-5 Class diagram of the Composite Design Pattern

By using the Composite Pattern, the CompositeVM will not need to define all

the representation and behavior of each visualization metaphor in it. What the VM

programmer who wants to implement the CompositeVM needs to do is to use the

same method of each visualization metaphor in it and add addition work he wants the

CompositeVM to do.

To take the Update method for an example, each VM has registered the variable

to Mapping Engine. In the Update method, each VM will update the registered

variable. If the CompositeVM does not use the Update method of each child VM, the

variable will not be updated.

5.4 The design of layout VM

In this section, we will describe the LayoutAlgorithm and the use of strategy

(8)

pattern.

The strategy pattern is useful for situations where it is necessary to dynamically

swap the algorithms used in an application. The strategy pattern is intended to provide

a means to define a family of algorithms, encapsulate each one as an object, and make

them interchangeable. The strategy pattern lets the algorithms vary independently

from clients that use them.[16]

Figure 5-6 The Strategy Design Pattern

With the Strategy Pattern we can change the Layout Algorithm dynamically. In

the DIVINEVM class we defined a Layout VM pointer which can reference to the

Layout VM which the VM wants to use. If we want to change the Layout VM, we can

use the setLayout method to swap the Layout VM.

數據

Figure 5-1 Inheritance architecture of Visualization Metaphor
Figure 5-2 The class diagram of an Observer Pattern.
Figure 5-3 The sequence diagram of an Observer Pattern.
Figure 5-4 The sequence diagram of the interaction of visualization metaphor
+3

參考文獻

相關文件

 Promote project learning, mathematical modeling, and problem-based learning to strengthen the ability to integrate and apply knowledge and skills, and make. calculated

Now, nearly all of the current flows through wire S since it has a much lower resistance than the light bulb. The light bulb does not glow because the current flowing through it

(1) principle of legality - everything must be done according to law (2) separation of powers - disputes as to legality of law (made by legislature) and government acts (by

During early childhood, developing proficiency in the mother-tongue is of primary importance. Cantonese is most Hong Kong children’s mother-tongue and should also be the medium

• Is the school able to make reference to different sources of assessment data and provide timely and effective feedback to students according to their performance in order

Using this formalism we derive an exact differential equation for the partition function of two-dimensional gravity as a function of the string coupling constant that governs the

This kind of algorithm has also been a powerful tool for solving many other optimization problems, including symmetric cone complementarity problems [15, 16, 20–22], symmetric

• But, If the representation of the data type is changed, the program needs to be verified, revised, or completely re- written... Abstract