Download My research interests include object

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Abstraction (computer science) wikipedia , lookup

Reactive programming wikipedia , lookup

Corecursion wikipedia , lookup

C++ wikipedia , lookup

Object-oriented programming wikipedia , lookup

C Sharp syntax wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Transcript
My research interests include object-oriented language design and decentralization programming design.
I have been designing and implementing a new object-oriented language named FlexibO. This language
supports a few new features such as resource control, on-line collaboration, colourful variables and
ownership control.
In this workshop, I will discuss about its flexible binding mechanism by the way of examples. Objectoriented programming languages have two kind of binding mechanisms: static binding and dynamic
binding. The former is useful in improve efficiency. Some languages such as C++ employ this approach.
The latter provides more flexibility to users. Java adopts this way to support its polymorphism. FlexibO
supports both static and dynamic mechanisms and entitles users to make their own decision on selection
of binding mechanism, which improves this language’s expressivity.
This short paper contains three sections. The first section gives an example in Java to show some
ambiguity and inconvenience with respect to the binding mechanism that Java supports. The second
section demonstrates how FlexibO implements this example. The final section summarizes this short
paper.
Section 1:
This section gives an example written in Java. This example consists of three classes: A, B and C.
public class A {
int data = 10;
static String species = "A";
public int getData( ) {
return data;
}
public static String getSpecies(){
return species;
}
}
public class B extends A {
int data = 20;
static String species = "B";
public int getData( ) {
return data;
}
public static String getSpecies(){
return species;
}
}
public class C extends A {
int data = 30;
static String species = "C";
public int getData( ) {
return data;
}
public static String getSpecies(){
return species;
}
}
public class Test {
public static void main(String[] args){
A ao = new C( );
System.out.print(ao.data);
System.out.println(ao.species);
System.out.print(ao.getData());
System.out.println(ao.getSpecies());
}
The results are as follows:
10A
30A
After declaring an object, the program firstly prints its attributes out directly, and then prints out the
attributes through invoking methods. It is noticeable that the results are different. The reason is that fields
in Java are always bound statically. In this case, whatever the value of ao is, its attributes always come
from the class A instead of C. However, methods in Java have different binding time. The binding of
static methods occurs at compilation time, but dynamic methods at runtime. The complicated binding
mechanisms lead to misunderstanding and confusion.
Furthermore, this program has code redundancy. Every class has to repeat the methods because the fields
within methods are determined at compilation time. Clearly, code redundancy causes a lot of
inconvenience especially to a system with complicated hierarchy.
Section 2:
The section presents how FlexibO demonstrates the example in section 1.
var A := class Value {
var dynamic data :=10;
var static species := “A”;
var dynamic getData := method [ ]{
return this.data;
};
var static getSpecies := method [ ]{
return this.species;
}
}
var B := class A {
var dynamic data := 20;
var static species := “B”;
}
var C := class B {
var dynamic data := 30;
var static species := “C”;
}
var ao := new C;
print ao.data;
print ao.species;
print ao.getData[];
print ao.getSpecies[];
The results are as follows:
30C30C
The results show that method invocations generate the same result as direct access to attributes.
If users replace “this.data” and “this.species” with “data” and “species”, the following result are printed
out.
30C10A
The results show method invocations produce different results.
FlexibO allows both static binding and dynamic binding. By default, it uses static binding. If the program
returns the attribute data directly, FlexibO binds this attribute statically. Whenever this method is
invoked, this attribute declared in A will be returned. Conversely, if users return this.data, the attribute
data will be determined at runtime basing on the value of this.
Section 3:
To sum up, this short paper firstly presents some ambiguity and inconvenience in Java regarding binding
mechanism through an example, and then demonstrates how FlexibO implements the same functionality
without ambiguity and code redundancy.