The Design of Class Mechanism for MOBY 1
Download
Report
Transcript The Design of Class Mechanism for MOBY 1
The Design of Class Mechanism
for MOBY
1
Earlier Software designers have to
choose between the following schemes
for the development
– Class rich languages like C++ or JAVA.
– Module rich languages like Standard ML.
2
Paper describes the design of the class mechanism
with a richer module system
– C++ and JAVA has the rich class mechanisms but week
module system
– Standard ML has rich Module System but lack
Class Mechanism
– Moby provides both rich Class and Module Mechanism
3
Class in the class mechanism has two
roles:
• Implementing Objects
• Supporting inheritance
Based on the above roles class have two
type of Clients:
•Object Client
•Class Client
4
MOBY : It is a ML-like language that
supports Class bases mechanisms.
MOBY has three mechanism to cover the
features of class based languages.
– Objects and Object Types.
– Classes and Class Interfaces.
– Modules and Module Signature.
5
Objects
Object in MOBY are collection of fields
and methods.
Member of Objects: fields + Methods
Operations on Objects:
» Select a field
» Update a field
» Invoke a method
6
Object Type
Object Type specifies which object members
client may use.
Object Types are nothing but are interfaces
of JAVA.
7
Objtype Point{
meth getX : Uint->Int
meth move:Int ->Point
}
Objtype CPoint extends Point with {
meth getC : Uint->Color
meth shade:Color ->CPoint
}
8
Typing
Typing in the MOBY is structural rather than
Name Subtyping as in JAVA.
Structural Subtyping has several variants:
– Width Subtyping
– Depth Subtyping
– Full Subtyping
9
Modules
Modules in Moby are like ML-Style languages.
Signature Controls the Visibility of the
definitions outside the Modules.
Modules may be nested .
Partial type revelation can be defined in
signatures.
type type-name <: type
10
Module PointTypes:{
objtype Point{
meth getX : Uint->Int
meth move : Int ->Point
}
Type CPoint <: Point
}{
………body of the PointTypes
}
11
MOBY Class
Defines the implementation of object
It contains the declaration of:
– fields
– Method
– Makers (which are constructors in C++ or
JAVA)
12
13
Class interface
It is a signature of the class
It is not interfaces as in JAVA.
It defines both object and class view.
14
15
Visibility
Internal Class View
External Class View
Internal Object View
External Object View
16
17
18
Class based features are realized in
MOBY:
Static Class Members
MOBY relies on Module system to support global
definition.
C++ private inheritance :
In MOBY Object Type implemented by subclass
is independent of the Object Type implemented by
its super class.
19
JAVA’s interfaces and C++’s multiple
inheritance with abstract base classes:
MOBY has the Structural sub typing relationship.
Final Classes:
We can have this by hiding the class in a module and
controlling the visibility of its methods
.
C++ friends and JAVA’s package scope:
MOBY uses the combination of modules and
partial type revelation
20