Support for Subtyping and Code Re-use in Timor

Size: px
Start display at page:

Download "Support for Subtyping and Code Re-use in Timor"

Transcription

1 Support for Subtyping and Code Re-use in Timor J. Leslie Keedy, Gisela Menger, Christian Heinlein Department of Computer Structures University of Ulm Ulm, Germany Abstract Unlike most object oriented programming languages Timor, which has been designed to support component development, replaces the class construct with separate constructs for defining types and their implementations (which are not types). It also distinguishes between behaviourally conforming subtyping and the inclusion of behaviourally deviant interfaces in the definition of derived types. The separation of types and implementations simplifies a separation of subtyping and subclassing, facilitating the re-use of implementations of one type to implement other, unrelated types. A further technique allows a type to be mapped onto an unrelated type with different method names, such that the latter's implementations can also be re-used to implement the former. The paper concludes by outlining a substantial example based on the Timor Collection Library.. Keywords: Software component, type, subtyping, subclassing, polymorphism, behavioural subtyping, base type, derived type, code re-use, code mapping. Introduction One of the most significant differences between object oriented and other programming languages is their explicit support for subtyping. The basic idea is that a type (the supertype) can be used as a base for defining a new type (the subtype). The subtype can redefine existing methods of the supertype and can add new members. Instances of subtypes can be assigned to variables of the supertype. This use of subtypes is known as inclusion polymorphism (Cardelli and Wegner, 1985). Because existing methods can be redefined, the behaviour of a subtype instance can be quite different from that of its supertype, even when used polymorphically as if it were an instance of the supertype. It is therefore useful to distinguish between behavioural and non-behavioural subtypes. Liskov and Wing (1994) have developed a behavioural notion of subtyping which differs from earlier definitions of the subtype relationship in that attention is paid not only to the redefinition of existing methods but also to the significance of new methods, which can affect Copyright 2002, Australian Computer Society, Inc. This paper appeared at the 40th International Conference on Technology of Object-Oriented Languages and Systems (TOOLS Pacific 2002), Sydney, Australia. Conferences in Research and Practice in Information Technology, Vol. 10. James Noble and John Potter, Eds. Reproduction for academic, not-for profit purposes permitted provided this text is included. the behaviour of existing methods in the presence of aliasing and also in a general computational environment that allows multiple users to share mutable objects. This strong definition of behavioural subtyping excludes some cases of subtyping which at first sight may appear to be behavioural, for example the relationship between a type Queue (as the supertype) and a type DoubleEnded- Queue (as the subtype). If a programmer uses a Double- EndedQueue instance as a Queue instance in his program it will, assuming that it has been defined and implemented in a reasonable way, work perfectly well as a Queue in his isolated context. But if the same object instance is accessed via other variables as a DoubleEndedQueue (e.g. using a method which inserts entries at the "wrong" end) it can exhibit properties which do not conform behaviourally with the usual definition of a Queue type. On the other hand there are many cases where a programmer has no intuitive expectation that a subtype will exhibit the same behaviour as a supertype. For example a supertype Button defined for use in a graphical user interface may have an operation push, the behaviour of which is specifically intended to vary depending on the kind of button which it actually is, as defined in more detail in particular subtypes. Definitions of the subtype relationship can also create problems at the implementation level. For example, in class-based languages the class construct is typically used to achieve both subtyping (i.e. a type relationship) and subclassing (a code re-use relationship), although these are often not compatible with each other, cf. e.g. Cook et al. (1990). For example the code of a supertype Queue can easily and effectively be re-used in a subtype Double- EndedQueue, but the fact that this is not a behavioural subtype suggests that in some applications the subtype relationship should be avoided; however this creates the dilemma that the code cannot be re-used. In this paper we describe how such issues are handled in the programming language Timor, which is currently being designed at the University of Ulm in Germany. The motivation for Timor is to develop an object-oriented language which is suitable for defining and implementing software components, whereby the word component here is to be understood in the original sense described by McIlroy (1968) (who used a sine routine as his example). Timor is intended to be suitable for developing software components of various sizes, including quite small components corresponding to fairly trivial classes in typical object oriented applications. This does not preclude an intention also to support the development of larger components, as the word is frequently understood today.

2 Timor supports not only single but also multiple inheritance, both at the type and implementation levels. However, in the present paper discussion is restricted to single inheritance, which is adequate to illustrate the three main issues which we wish to discuss. In section 2 we describe the separation of types and implementations, which in most object oriented languages can only be simulated via inheritance (at the cost of introducing unintended types). Sections 3 and 4 outline the differing treatment of behavioural and non-behavioural subtypes. Sections 5 to 8 show how code can be flexibly re-used to implement types which are not necessarily related to each other. An example is provided in section 9. Section 10 provides a comparison with related work and section 11 summarises the paper, adding some final remarks. In later papers we shall describe how these ideas are extended to encompass multiple (and repeated) type and implementation inheritance. Distinguishing s and Implementations In a component development environment it is important to be able to develop different implementations for the same type (Figure 1). For example a type List might be implemented as an array, a linked list, etc. This simple requirement led us to replace the class concept with a concept which distinguishes between types and their implementations. Implementation 3 Implementation 2 Implementation 1 Figure 1: A with Multiple Implementations A Timor type is defined as follows 1 : type Queue { maker init(int maxsize); op void insertatback(element e) throws FullEx; op ELEMENT removeatfront() throws EmptyEx; enq ELEMENT front() throws EmptyEx; enq int length(); This can have several implementations. Here is an arraybased implementation: 1 The qualifier maker introduces an explicitly named constructor. The qualifier op introduces an operation (which can modify the state of an instance of the type), enq introduces an enquiry (which cannot modify the instance's state). The distinction between op and enq methods is important for example for defining qualifying types with bracket routines, cf. Keedy et al. (1997), Keedy et al. (2000), but is not significant for the present discussion. The type ELEMENT can be thought of as any relevant type. Timor supports a generic concept along the lines described in Evered (1997), Evered et al. (1997), but again this is not directly relevant to our discussion and is not described here. impl ArrayQueue1 of Queue { ELEMENT[] thearray; int maxsize; int size = 0; int front = 0; int back = 0; maker init(int maxsize){ this.maxsize = maxsize; thearray = new ELEMENT[maxSize]; op void insertatback(element e) throws FullEx { if (size < maxsize) {thearray[back] = e; back++; if (back == maxsize) back = 0; size++; else throw new FullEx(); op ELEMENT removeatfront() throws EmptyEx { if (size > 0) {ELEMENT temp = thearray[front]; front++; if (front == maxsize) front = 0; size--; return temp; else throw new EmptyEx(); enq ELEMENT front() throws EmptyEx { if (size > 0) return thearray[front]; else throw new EmptyEx(); enq int length() {return size; There are many other possible implementations of Queue, which could be written as separate implementation components and given different names. The important point here is that the behaviour of different implementations of a type must be equivalent to each other. We call this behavioural equivalence. It differs from behavioural conformity in that a subtype relationship is not involved, i.e. the behaviour of members cannot be re-specified and new public members cannot be added in an implementation. Defining the Behaviour of Components In a situation where components are developed and used by different groups of programmers it is important that all concerned have a clear understanding of how components behave. We have just introduced the term behavioural equivalence and have already referred in the introduction to the notion of behavioural conformity as a concept associated with subtyping. Formally, both of these notions must be defined in terms of a formal specification. We intend to add a specification technique in later versions of Timor, but in the first version behavioural equivalence can only be defined intuitively, as the equivalent fulfilment by different implementations of a type definition (with the help of comments). Similarly behavioural conformity has initially to be understood intuitively, in the spirit of the Liskov and Wing definition. Suppose, however, that we already had a specification technique (and that it were powerful enough to describe the behaviour of types to a degree of detail and accuracy that we need). This would mean that different implementations of a type could only be described as behaviourally equivalent provided that they fulfil the specification for the type. Similarly subtype specifications could only be described as behaviourally conforming in so far as they fulfil the specification of the supertype. Put another way, an "implementation" of a type would not be a valid im-

3 plementation if it did not fulfil the specification of the type, and a "subtype" specification would not define a behaviourally conforming subtype if it did not conform with the specification of the supertype. We assume in this context that a formal specification would be precise in the sense of stating requirements which have to be fulfilled, but at the same time it could leave freedom for different actual behaviours to fulfil these requirements. Thus for example an abstract type Collection might specify non-deterministically that following an insert operation the collection size would either be increased by one or would not change. In this way a type Bag (which accepts duplicates), a type Set (which ignores duplicates) and a type Table (which throws an exception when an attempt is made to insert a duplicate) could be behavioural subtypes of the type Collection. In some cases it can also be appropriate to provide a null specification, in which case any syntactically correct implementation fulfils the specification and any syntactically correct subtype definition conforms behaviourally with its supertype. Derived s Timor supports the definition of types on the basis of other types in a form which resembles the conventional object-oriented style of subtyping. Such types are known as derived types (Figure 2). Base Derived Figure 2: A Base with a Derived In definitions of derived types a distinction is drawn between genuine subtyping, based on the behavioural notion, and the use of a base type simply as a mechanism for including interface definitions in a new type without implying a subtyping relationship. Where behavioural conformity is intended the supertype is introduced by the keyword extends, e.g. type Collection {... op void insert(element e) throws DuplicateEx; type Bag extends Collection redefines { op void insert(element e); // the insert method for a Bag // does not throw a DuplicateEx. { /* no new methods in this example */ A non-behavioural relationship is introduced by the keyword includes, e.g. type DoubleEndedQueue includes Queue { maker init(int maxsize); op void insertatfront(element e) throws FullEx; op ELEMENT removeatback() throws EmptyEx; enq ELEMENT back() throws EmptyEx; Because the inclusion of a base type in another type does not imply a subtyping relationship, component instances of the derived type cannot be assigned to variables of the base type. Thus a component of type DoubleEndedQueue cannot be assigned to a Queue variable, but a component of type Bag can be assigned to a variable of type Collection. If a method of a supertype is changed in a derived type (for extensions in a behaviourally conforming manner) this must appear in a redefines clause. In principle this requires a new formal specification of the method(s) involved, but in the first version of Timor this is strictly speaking only relevant for single inheritance 2 in cases where some exceptions defined in a method of the supertype cannot be thrown in the derived type, as is illustrated in the type Bag. Since similar changes can be defined for methods of included types, these may also appear in a redefines clause. As the intended behaviour of a method can in principle change in the first version of Timor even if the signature does not, programmers must list such members in a redefines clause even where the signature does not change. In practice the redefines clause can be viewed as a list of methods which in an implementation can be overridden in the object oriented sense. Such changes must conform behaviourally with an extends supertype but not with an includes base type. We anticipate that some (though not exhaustive) checking of behavioural conformity for methods appearing in a redefines clause may be possible when a specification technique is added. Implementing s An implementation of a type is considered to be an implementation of all the members of the type. This can take several forms: (a) A type (including a derived type) can have a completely new implementation (Figure 3). Base Derived Implementation Figure 3: An Independent Implementation of a Derived according to the Information Hiding Principle This is well suited to the information hiding principle (Parnas, 1972). The new implementation of the methods of supertypes must conform with the specifications of the supertypes (where relevant as redefined in the derived type). The implementation of new and 2 Timor supports multiple type inheritance, i.e. more than one type can appear in the extends and/or includes clauses. In that case the redefines clause is also used for the clarification of name collisions.

4 redefined members must conform with the specification of the derived type. (b) A type (including a derived type) can re-use implementations of other types (indicated by the keyword reuses). In contrast with standard OO practice a subtype relation between the type of the new implementation and the types of its re-used implementations need not (but can) exist. Thus code re-use can be completely decoupled from subtyping and from the inclusion of interfaces. A reuses clause can designate a specific implementation to be re-used (Figure 4). This typically reflects the conventional object oriented style of code inheritance, as is illustrated in section 6. A This relationship need not exist Another Implementation of some type Implementation of another type re-using it Figure 4: Reuse of a Specific Implementation Alternatively, it can designate a type, any of whose implementations can be re-used (at the level of the public members) (Figure 5). This leads to a quite different style of code re-use, illustrated in section 7. A Another Implementation 3 Implementation 2 Implementation 1 Implementation of another type re-using any of its implementations Figure 5: Reuse of any Implementation of a (c) A type can be mapped to another type, and in this way re-use its implementations, again without implying a type relationship (Figure 6). This is illustrated in section 8. Implementation 3 Implementation 2 Implementation 1 A A Mapping Implementation 1 A mapped to it for code re-use Figure 6: Mapping a to another Finally, Timor also allows the possibility of typeless implementations. These are free-standing implementations which have no effect on the type system, but which can be freely re-used in the implementations of types. Simulating Subclassing via Code Re-use In section 2 we illustrated an implementation Array- Queue1 of a type Queue and in section 4 we showed how the type Queue might have a (non-behavioural) derived type DoubleEndedQueue. Here an implementation of DoubleEndedQueue reuses the implementation Array- Queue1 in a way which resembles the conventional code inheritance technique (i.e. subclassing): impl ArrayDEQ1 of DoubleEndedQueue reuses ArrayQueue1 { op void insertatfront(element e) throws FullEx{ if (size < maxsize) {front--; if (front < 0) front = maxsize - 1; thearray[front] = e; size++; else throw new FullEx(); op ELEMENT removeatback() throws EmptyEx{ if (size > 0) {back--; if (back < 0) back = maxsize - 1; size--; return thearray[back]; else throw new EmptyEx(); enq ELEMENT back() throws EmptyEx { if (size > 0) {int i = back - 1; if (i < 0) i = maxsize - 1; return thearray[i]; else throw new EmptyEx(); In this example, the implementation of the derived type nominates an implementation of the type which is to be re-used (Figure 7). All the methods of a re-used implementation whose headers match the methods of the type being implemented are "inherited" (along with any data structures and methods which they need); any other methods are ignored. Implementation: ArrayQueue1 Base : Queue Implementation: ArrayDEQ1 Derived : DoubleEndedQueue Figure 7: Simulating Conventional Subclassing Here we see one of the advantages of explicitly naming constructors (rather than using the type name as a constructor name, as in Java). In appropriate cases as here with respect to the constructor from ArrayQueue1 defined in section 2 a constructor can be re-used in an implementation of a different type without having to be separately coded (and where appropriate explicitly call a constructor of the supertype). The nomination of a specific implementation of some other type for re-use is typical in cases where code re-use follows the conventional OO inheritance paradigm of incrementally inheriting from base types (whether or not the inheritance is behavioural), where access is needed to

5 data structures. While this style of code re-use is possible in Timor, it is not the preferred style, as it violates the information hiding principle and it does not result in modular components. We now illustrate the alternative style, which is possible because code re-use can be decoupled from type relationships. Code Re-Use without Relationships Because for subtyping reasons DoubleEndedQueue was defined by including Queue rather than by extending it, the two types are not related from the polymorphic viewpoint. In practice DoubleEndedQueue could therefore have been defined as a separate type, as follows: type DoubleEndedQueue{ maker init(int maxsize); op void insertatfront(element e) throws FullEx; op void insertatback(element e) throws FullEx; op ELEMENT removeatfront() throws EmptyEx; op ELEMENT removeatback() throws EmptyEx; enq ELEMENT front() throws EmptyEx; enq ELEMENT back() throws EmptyEx; enq int length(); Regardless whether DoubleEndedQueue was defined as a separate type or as a derived type, it has the above interface, and it can be treated as a separate type for implementation purposes. (This holds also for a behaviourally conforming subtype: any type can be implemented using any of the techniques described in section 5, regardless of its type relationships.) A significant advantage of implementing any type without reusing a specific implementation of another type (i.e. without using the technique illustrated in section 6) is that this can be done in conformance with the information hiding principle. The type DoubleEndedQueue could have several such implementations, e.g. ArrayDEQ, Linked- ListDEQ which do not re-use other code. Given such independent implementations, all of them could potentially be re-used to provide implementations of Queue. The following illustrates how this is achieved in Timor: impl Queue1 of Queue reuses DoubleEndedQueue {/* no re-implemented methods */ The reuses clause in this example nominates a type rather than an implementation, indicating that any implementation of the type can be re-used (Figure 8). This has the advantage that for any new implementation of DoubleEndedQueue there is automatically a new implementation of Queue. The basic rule is that any method which appears in the re-used type with an identical signature is re-used, unless it is overridden in the new implementation 3. 3 Overriding is not illustrated in our examples, but it does not differ significantly from other overriding techniques which allow the code of an overridden method to be invoked using a super construct. This relationship need not exist Implementation: Implementation 1: LinkedListDEQ ArrayDEQ DoubleEndedQueue Queue Implementation 1: Queue 1 Figure 8: Reusing any Implementation of a Some methods of DoubleEndedQueue (e.g. insertat- Front) cannot be explicitly invoked by clients of Queue. Whether such redundant methods (and fields) are removed from the implementation Queue1 depends on the compiler (or possibly the component developer). They can of course only be removed if an analysis by the compiler shows that they genuinely are redundant (e.g. if methods are not invoked from the methods which are required). Mapping s onto Other s Implementations of the type DoubleEndedQueue could be easily re-used to implement unrelated types which do not have matching member definitions in their types. For example a type Stack might be defined as follows: type Stack { maker init(int maxsize); op void push(element e) throws FullEx; op ELEMENT pop() throws EmptyEx; enq ELEMENT top() throws EmptyEx; enq int length(); To allow the re-use of implementations of Double- EndedQueue for Stack the following map can be provided: map StackMap1 from Stack to DoubleEndedQueue { op void push(element e) => insertatfront; op ELEMENT pop() => removeatfront; enq ELEMENT top() => front; Members of the mapped type which already match (e.g. in this example the length method and the constructor) can be omitted from the map. Unmapped members must be implemented in some other way. When such a map exists, any implementation of the map's destination type (here DoubleEndedQueue) can be used to implement the mapped type, e.g. impl Stack1 of Stack reuses DoubleEndedQueue via StackMap1 { This relationship is illustrated in Figure 9. Implementation: Implementation 1: LinkedListDEQ DoubleEnded- Queue ArrayDEQ Implementation 1: Stack1 Stack- Map1 Stack Figure 9: Mapping a Stack onto a Double Ended Queue

6 In the first version of Timor maps are kept simple, i.e. there must be an exact signature match; only the names of members and of parameters may differ between a mapped member and the member onto which it is mapped. Larger Scale Application We now briefly describe a realistic library of types and implementations, developed using the concepts of behavioural derived types and code re-use. This is the Timor Collection Library, the design of which is based on one co-author's doctoral thesis (Menger, 2000). The aim was to provide a library of collection types and implementations which orthogonally support the following properties: (a) handling the duplication of elements in three forms: collections which allow duplicate elements to be inserted, collections which ignore attempts to insert duplicates, collections which signal as exceptions attempts to insert duplicates. (b) handling the ordering of elements in three forms: unordered, user-ordered, automatically sorted on the basis of user-defined criteria. This leads to nine (three times three) concrete types, which are organised in a behaviourally conforming hierarchy that also includes four abstract types (Collection, DuplicateFreeCollection, UserOrderedCollection, SortedCollection). Multiple type inheritance (not described in this paper) was used to achieve a maximum of behavioural subtyping among related types. Implementing this library using the re-use technique primarily involves coding only two of the concrete types: List: duplicates allowed, user-ordered; and SortedList: duplicates allowed, sorted. Furthermore implementations of the type List can be almost completely re-used in implementations of the type SortedList. In addition two typeless implementations are needed to provide trivially redefined routines which bracket the insert routines of List and SortedList. These check for attempts to insert duplicate elements into appropriate types, in one case throwing an exception. To provide alternative implementations of the entire library (as arrays, linked lists, doubly linked lists) requires only a new implementation of List and (a few methods of) SortedList. The implementations which carry out duplicate checking can be re-used with any implementations of the List and SortedList types. Customised implementations of some types can of course be provided separately, e.g. an implementation of Set (duplicates ignored, unordered) and of Table (duplicates signalled, unordered) as bit lists, for cases where the element types can be enumerated. The result is a fully orthogonal, behaviourally conforming collection library with a maximum of code re-use as well as conformance with the information hiding principle. It can easily be extended by users to support their own specialised types, and it can be quickly re-implemented using new data structures. Related Work Code reuse via inheritance is often considered to be the most important benefit of object oriented programming. But earlier OO languages, where classes unify types and their implementations (e.g. Eiffel, C++), suffer from the problem that subtyping and subclassing do not always fit well together, cf. e.g. LaLonde and Pugh (1991). Nevertheless, even without language support for a clear separation between types and implementations, it is sometimes possible to achieve a surprisingly high degree of separation between types and subtyping on the one hand and implementations and code reuse on the other hand. Taking C++ (Stroustrup, 1997) as an example, "pure" abstract classes (i.e. classes containing only pure virtual functions) can be used to model a type hierarchy, while normal classes can be used to build an independent implementation hierarchy. Private or protected inheritance, which prevents a subtype relationship between base and derived classes, can be used to represent the implements and reuses relationships of Timor. In combination with access or using declarations, even the includes relationship can be simulated, without creating a subtype relationship. But as C++ has not been designed to support such a clean separation of types and implementations, its enforcement by the programmer is somewhat artificial and more or less tedious. Especially in cases where an implementation of a completely unrelated type is to be reused to implement a type, it is necessary to explicitly merge the abstract methods of the type being implemented with the corresponding methods of the reused implementation by providing definitions of the methods which forward their calls to this implementation. Furthermore, simply reusing all implementations of a type to implement another type, requires similar method definitions which delegate their work to the methods of the reused type. For more than a decade the relationship between subtyping and subclassing has been discussed in the academic area and languages (e.g. Sather, Signatures and Brew, Java, Theta, Tau) have been put forward which attempt to separate types and implementations with the aim of improving both. Sather (Stoutamire and Omohundro, 1996) is a descendant of Eiffel (Meyer, 1992) with a fundamentally changed type system. Different kinds of relationships may coexist in a single hierarchy, which has an abstract class as its root. Abstract classes (without code) model type relationships, while concrete classes (which may only appear in leaf nodes) are subtypes of the abstract class(es) which they implement and are themselves types. Furthermore, abstract classes can be added retrospectively to the hierarchy as supertypes of existing classes. Code reuse is achieved by means of an inclusion mechanism, which

7 copies code at the source level. Partial classes are classes which can contain code but which are not associated with a type; they can neither be instantiated nor used for variable declarations. Including code from other classes does not imply a type relationship. Static type safety is maintained by means of contravariant type rules. This approach suffers from the fact that types and implementations are not fully decoupled from each other, i.e. concrete classes are also types. Signatures (Baumgartner and Russo, 1995) have been suggested (and implemented in the GNU C++ compiler) as an extension of C++ which supports the separation of types and implementations more directly and naturally. The basic idea is that signatures, like abstract classes in Sather, represent types which can be implemented in classes, also with the possibility that they can be retrospectively specified. However, signatures cannot serve as complete type definitions, as they may not contain constructors. Unlike Sather they are not part of the class hierarchy. But as signatures have been designed as a conservative extension of C++, they are unable to overcome inherent deficiencies of the base language, especially the fact that classes are also types. With Brew (Baumgartner et al., 1996), the signature concept has been realized in a Java-based language. Java interface types (Arnold et al., 2000) have similarities with both Sather's abstract classes and with signatures. However, the separation of interfaces from their implementations is more explicit and easier to understand than the Sather approach, because, as with signatures, interfaces are not part of the class hierarchy. On the other hand not only are classes also types, but subclassing also implies a subtype relation. Principles such as information hiding and programming to interfaces can easily be circumvented by using classes without giving up subtype polymorphism (as in Sather). Nevertheless the Java type system is much simpler than that of Sather. Like signatures, Java interfaces may not contain constructors. In contrast with both Sather and the signatures approach, interfaces may not be defined retrospectively. In Theta (Liskov et al., 1994) types are cleanly distinguished from classes, and the idea of multiple implementations is supported. Subtyping occurs between types, while classes are not types but only implementations of types, so that code reuse is as flexible as in Sather. Constructors may not appear on the type interface, thereby hindering strict programming to interfaces and also induction based type verification (because there is no starting point). Nevertheless, the clear distinction between types and implementations is a significant step forward. Tau (Schmolitzky, 1999) is a radical adaptation of Java which realises the notion of abstract typing. The approach is similar to that found in Theta, in that subtyping occurs between types (called interfaces in Tau). Classes are not types, and subclassing does not imply any type relationship. Tau also supports typeless classes (similar to partial classes in Sather), which are intended only for code reuse. A decisive further step is taken in Tau, namely that, in contrast with previous languages, type interfaces can include abstract constructors. Timor is based on the concept of abstract typing in Tau and adds some new features which are intended to be useful for developing software components. It emphasises the significance of behavioural subtyping by permitting a programmer to define derived types in a subtype relationship (where behavioural conformity is intended), while also allowing type interfaces to be included in derived types without implying such a relationship. Both forms of derived types allow inherited methods to be redefined, but they must be listed in a redefines clause, thus making it easy to identify the hot spots of an implementation. Code reuse can be achieved in a similar manner to Tau, in a way which resembles subclassing. However, Timor goes further than Tau by allowing a type to be named in a reuses clause, thereby indicating that any implementation of that type can be re-used, with the advantage that the information hiding principle can also be preserved between implementations. This applies also to the mapping technique, which allows one type interface to be mapped onto another for code reuse purposes. Summary and Final Remarks The paper has briefly described how the new programming language Timor 4 handles a number of issues relating to types and subtyping as well as implementations and code re-use. Aspects relating to multiple type inheritance and multiple code re-use have, however, not been discussed, as these raise a different set of issues which will be discussed in a future paper. Motivated by the idea of regarding object oriented units potentially as general purpose components for use in a wide range of application systems, the language distinguishes between types and their implementations (which are not also types). This division of the traditional class construct into separate units has a number of advantages. From the viewpoint of component development and use it allows a single type to be implemented in different ways (e.g. reflecting different time and space tradeoffs), and these separate implementations can be sold/bought as separate components. Thus the existence of multiple implementations for a type does not necessarily imply that more than one implementation will be used in a particular application program or system 5. It does, however, help to simplify some of the problems associated with subtyping and subclassing. A user of components representing types and their implementations needs to understand how these are likely to behave, especially with respect to the issue of subtyping. In derived types, which represent a variation of the traditional form of subtyping, a distinction is drawn between extending a supertype in a behaviourally conforming 4 The current state of Timor is that it is nearing the end of the design stage. No compiler is yet available. 5 Techniques used in Timor for handling the coexistence of different implementations in a single program and the selection of particular implementations are not discussed in this paper, as these themes are not relevant to the issues of subtyping which the paper addresses.

8 manner and including base types to which the derived type need not conform behaviourally. In the absence of a specification technique in the first version of Timor, the behavioural requirement of extension subtypes must be regarded as a statement of intent by the designer rather than a feature which can be checked by the compiler. Nevertheless there is provision for a redefines clause in derived types which allows the designer to indicate where behavioural changes occur. At the implementation level Timor supports the conventional code inheritance technique (using a reuses clause which typically nominates an implementation to be reused). However, as the example in section 6 shows, this technique effectively encourages programmers to circumvent the information hiding principle by exporting major data structures. This can be avoided by using the reuses clause to designate a type, which need not be a supertype of the type being implemented. As described in section 7, the information hiding principle is thereby preserved and any implementation of the designated type is allowed to be re-used. Finally a mapping technique is introduced (section 8) which enhances the possibilities of code re-use by allowing methods of one type to be mapped onto methods of another type such that the mapped type can be implemented by re-using implementations of the type onto which it is mapped. At present this technique requires an exact match of signatures (except the names of methods and their parameters), but we anticipate that the technique will be made more flexible in future versions of Timor. The example of the Timor Collection Library, briefly outlined in section 9, provided us with confirmation of our view that it is worthwhile in the design of a new language to keep orthogonal ideas (such as types and implementations, subtyping and subclassing, behavioural conformity and behavioural divergence) separate, even if the language gets marginally larger. It is not a significant problem later to allow short-cuts for simple cases, such as allowing "classes" in the form of implementations which implicitly define their own types. In summary Timor supports ideas which have already been proven in other languages and adds new ones which are considered to be useful for designing and implementing software components. Acknowledgement: Special thanks are due to Dr. Mark Evered and Dr. Axel Schmolitzky for their invaluable contributions to the development of Timor ideas. References ARNOLD, K., GOSLING, J., and HOLMES, D. (2000): The Java Programming Language, Third Edition, Addison-Wesley. BAUMGARTNER, G., LÄUFER, K., and RUSSO, V.F. (1996): On the Interaction of Object-Oriented Design Patterns and Programming Languages, Department of Computer Sciences, Purdue University, West Lafayette, IN. BAUMGARTNER, G., and RUSSO, V.F. (1995): Signatures: A Language Extension for Improving Abstraction and Subtype Polymorphism in C++. Software - Practice and Experience 25(8): CARDELLI, L., and WEGNER, P. (1985): On Understanding s, Data Abstraction and Polymorphism. Computing Surveys 17(4): COOK, W., HILL, W., and CANNING, P. (1990): Inheritance is Not Subtyping. 17th ACM Symposium on Principles of Programming Languages: EVERED, M. (1997): Unconstraining Genericity. 24th International Conf. on Technology of Object- Oriented Languages and Systems, Beijing: EVERED, M., KEEDY, J.L., MENGER, G., and SCHMOLITZKY, A. (1997): Genja - A New Proposal for Genericity in Java. 25th International Conf. on Technology of Object-Oriented Languages and Systems, Melbourne. KEEDY, J.L., ESPENLAUB, K., MENGER, G., SCHMOLITZKY, A., and EVERED, M. (2000): Software Reuse in an Object Oriented Framework: Distinguishing s from Implementations and Objects from Attributes. 6th International Conference on Software Reuse, Vienna. KEEDY, J.L., EVERED, M., SCHMOLITZKY, A., and MENGER, G. (1997): Attribute s and Bracket Implementations. 25th International Conf. on Technology of Object-Oriented Languages and Systems, Melbourne. LALONDE, W.R., and PUGH, J.R. (1991): Subclassing _ Subtyping _ Is-a. Journal of Object-Oriented Programming January 1991: LISKOV, B., CURTIS, D., DAY, M., GHEMAWAT, S., GRUBER, R., JOHNSON, P., and MYERS, A.C. (1994): Theta Reference Manual, MIT Laboratory for Computer Science, Cambridge, MA. LISKOV, B., and WING, J.M. (1994): A Behavioral Notion of Subtyping. ACM Transactions on Programming Languages and Systems 16(6): MCILROY, M.D. (1968): Mass Produced Software Components. NATO Conference on Software Engineering, NATO Science Committee, Garmisch, Germany: 88-98, Petrocelli-Charter. MENGER, G. (2000): Unterstützung für Objektsammlungen in statisch getypten objektorientierten Programmiersprachen (Support for Object Collections in Statically d Object Oriented Languages): Dept. of Computer Structures, University of Ulm, Germany. MEYER, B. (1992): Eiffel: the Language. New York, Prentice-Hall.

9 PARNAS, D.L. (1972): On the Criteria To Be Used in Decomposing Systems into Modules. Communications of the ACM 15(12): SCHMOLITZKY, A. (1999): Ein Modell zur Trennung von Vererbung und Typabstraktion in objektorientierten Sprachen (A Model for Separating Inheritance and Abstraction in Object Oriented Languages): Dept. of Computer Structures, University of Ulm, Germany. STOUTAMIRE, D., and OMOHUNDRO, S. (1996): The Sather 1.1 Specification, International Computer Science Institute, Berkley, CA. STROUSTRUP, B. (1997): The C++ Programming Language (third edition), Addison Wesley.

JOURNAL OF OBJECT TECHNOLOGY

JOURNAL OF OBJECT TECHNOLOGY JOURNAL OF OBJECT TECHNOLOGY Online at http://www.jot.fm. Published by ETH Zurich, Chair of Software Engineering JOT, 2004 Vol. 3, No. 10, November-December 2004 Inheriting Multiple and Repeated Parts

More information

Taking Information Hiding Seriously in an Object Oriented Context

Taking Information Hiding Seriously in an Object Oriented Context Taking Information Hiding Seriously in an Object Oriented Context J. Leslie Keedy, Gisela Menger and Christian Heinlein Department of Computer Structures University of Ulm D-89069 Ulm Federal Republic

More information

JOURNAL OF OBJECT TECHNOLOGY

JOURNAL OF OBJECT TECHNOLOGY JOURNAL OF OBJECT TECHNOLOGY Online at http://www.jot.fm. Published by ETH Zurich, Chair of Software Engineering JOT, 2004 Vol. 3, No. 1, January-February 2004 Qualifying Types with Bracket Methods in

More information

Late-bound Pragmatical Class Methods

Late-bound Pragmatical Class Methods Late-bound Pragmatical Class Methods AXEL SCHMOLITZKY, MARK EVERED, J. LESLIE KEEDY, GISELA MENGER Department of Computer Structures University of Ulm 89069 Ulm, Germany {axel, markev, keedy, gisela@informatik.uni-ulm.de

More information

JOURNAL OF OBJECT TECHNOLOGY

JOURNAL OF OBJECT TECHNOLOGY JOURNAL OF OBJECT TECHNOLOGY Online at http://www.jot.fm. Published by ETH Zurich, Chair of Software Engineering JOT, 2004 Vol. 3, No. 10, November-December 2004 Diamond Inheritance and Attribute Types

More information

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism Block 1: Introduction to Java Unit 4: Inheritance, Composition and Polymorphism Aims of the unit: Study and use the Java mechanisms that support reuse, in particular, inheritance and composition; Analyze

More information

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

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1 Object-Oriented Languages and Object-Oriented Design Ghezzi&Jazayeri: OO Languages 1 What is an OO language? In Ada and Modula 2 one can define objects encapsulate a data structure and relevant operations

More information

Object Oriented Issues in VDM++

Object Oriented Issues in VDM++ Object Oriented Issues in VDM++ Nick Battle, Fujitsu UK (nick.battle@uk.fujitsu.com) Background VDMJ implemented VDM-SL first (started late 2007) Formally defined. Very few semantic problems VDM++ support

More information

PROCESS DEVELOPMENT METHODOLOGY The development process of an API fits the most fundamental iterative code development

PROCESS DEVELOPMENT METHODOLOGY The development process of an API fits the most fundamental iterative code development INTRODUCING API DESIGN PRINCIPLES IN CS2 Jaime Niño Computer Science, University of New Orleans New Orleans, LA 70148 504-280-7362 jaime@cs.uno.edu ABSTRACT CS2 provides a great opportunity to teach an

More information

CPS 506 Comparative Programming Languages. Programming Language

CPS 506 Comparative Programming Languages. Programming Language CPS 506 Comparative Programming Languages Object-Oriented Oriented Programming Language Paradigm Introduction Topics Object-Oriented Programming Design Issues for Object-Oriented Oriented Languages Support

More information

Safely Extending Procedure Types to Allow Nested Procedures as Values 1

Safely Extending Procedure Types to Allow Nested Procedures as Values 1 Safely Extending Procedure Types to Allow Nested Procedures as Values 1 Christian Heinlein Dept. of Computer Structures, University of Ulm, Germany heinlein@informatik.uni ulm.de Abstract The concept of

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract Classes

More information

What s Conformance? Conformance. Conformance and Class Invariants Question: Conformance and Overriding

What s Conformance? Conformance. Conformance and Class Invariants Question: Conformance and Overriding Conformance Conformance and Class Invariants Same or Better Principle Access Conformance Contract Conformance Signature Conformance Co-, Contra- and No-Variance Overloading and Overriding Inheritance as

More information

Chapter 5 Object-Oriented Programming

Chapter 5 Object-Oriented Programming Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares

More information

[ L5P1] Object-Oriented Programming: Advanced Concepts

[ L5P1] Object-Oriented Programming: Advanced Concepts [ L5P1] Object-Oriented Programming: Advanced Concepts Polymorphism Polymorphism is an important and useful concept in the object-oriented paradigm. Take the example of writing a payroll application for

More information

JOURNAL OF OBJECT TECHNOLOGY

JOURNAL OF OBJECT TECHNOLOGY JOURNAL OF OBJECT TECHNOLOGY Online at http://www.jot.fm. Published by ETH Zurich, Chair of Software Engineering JOT, 2005 Vol. 4, No. 7, September - October 2005 Statically Qualified Types in Timor J.

More information

Chapter 10 Classes Continued. Fundamentals of Java

Chapter 10 Classes Continued. Fundamentals of Java Chapter 10 Classes Continued Objectives Know when it is appropriate to include class (static) variables and methods in a class. Understand the role of Java interfaces in a software system and define an

More information

Subtypes and Subclasses

Subtypes and Subclasses Subtypes and Subclasses 6.170 Lecture 14 Fall - ocw.mit.edu Reading: Chapter 7 of Program Development in Java by Barbara Liskov 1 Subtypes We have used closed arrows in module dependence diagrams and object

More information

Today's Agenda. References. Open Closed Principle. CS 247: Software Engineering Principles. Object-Oriented Design Principles

Today's Agenda. References. Open Closed Principle. CS 247: Software Engineering Principles. Object-Oriented Design Principles CS 247: Software Engineering Principles Reading: none Object-Oriented Design Principles Today's Agenda Object-Oriented Design Principles - characteristics, properties, and advice for making decisions that

More information

Lecture Notes on Programming Languages

Lecture Notes on Programming Languages Lecture Notes on Programming Languages 85 Lecture 09: Support for Object-Oriented Programming This lecture discusses how programming languages support object-oriented programming. Topics to be covered

More information

CMSC 132: Object-Oriented Programming II

CMSC 132: Object-Oriented Programming II CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation

More information

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Inheritance Consider a new type Square. Following how we declarations for the Rectangle and Circle classes we could declare it as follows:

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

An Approach to Behavioral Subtyping Based on Static Analysis

An Approach to Behavioral Subtyping Based on Static Analysis TACoS 04 Preliminary Version An Approach to Behavioral Subtyping Based on Static Analysis Francesco Logozzo 1 STIX - École Polytechnique F-91128 Palaiseau, France Abstract In mainstream object oriented

More information

Design by Contract in Eiffel

Design by Contract in Eiffel Design by Contract in Eiffel 2002/04/15 ctchen@canthink.com.com.tw.tw Reference & Resource Bertrand Meyer, Object-Oriented Oriented Software Construction 2nd,, 1997, PH. Bertrand Meyer, Eiffel: The Language,,

More information

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

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language Categories of languages that support OOP: 1. OOP support is added to an existing language - C++ (also supports procedural and dataoriented programming) - Ada 95 (also supports procedural and dataoriented

More information

Hypertext A Case Study of Formal Object-Oriented Software Development

Hypertext A Case Study of Formal Object-Oriented Software Development Hypertext A Case Study of Formal Object-Oriented Software Development Andreas Rüping Forschungszentrum Informatik (FZI) Bereich Programmstrukturen Haid-und-Neu-Straße 10-14 D-76131 Karlsruhe e-mail: rueping@fzi.de

More information

The Contract Pattern. Design by contract

The Contract Pattern. Design by contract The Contract Pattern Copyright 1997, Michel de Champlain Permission granted to copy for PLoP 97 Conference. All other rights reserved. Michel de Champlain Department of Computer Science University of Canterbury,

More information

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107 A abbreviations 17 abstract class 105 abstract data types 105 abstract method 105 abstract types 105 abstraction 92, 105 access level 37 package 114 private 115 protected 115 public 115 accessors 24, 105

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Implementing Object Equivalence in Java Using the Template Method Design Pattern

Implementing Object Equivalence in Java Using the Template Method Design Pattern Implementing Object Equivalence in Java Using the Template Method Design Pattern Daniel E. Stevenson and Andrew T. Phillips Computer Science Department University of Wisconsin-Eau Claire Eau Claire, WI

More information

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages

More information

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE Abstract Base Classes POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors class B { // base class virtual void m( ) =0; // pure virtual function class D1 : public

More information

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors CSC 330 OO Software Design 1 Abstract Base Classes class B { // base class virtual void m( ) =0; // pure virtual

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract

More information

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

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia Object Oriented Programming in Java Jaanus Pöial, PhD Tallinn, Estonia Motivation for Object Oriented Programming Decrease complexity (use layers of abstraction, interfaces, modularity,...) Reuse existing

More information

Objects, Subclassing, Subtyping, and Inheritance

Objects, Subclassing, Subtyping, and Inheritance Objects, Subclassing, Subtyping, and Inheritance Brigitte Pientka School of Computer Science McGill University Montreal, Canada In these notes we will examine four basic concepts which play an important

More information

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods. Inheritance Inheritance is the act of deriving a new class from an existing one. Inheritance allows us to extend the functionality of the object. The new class automatically contains some or all methods

More information

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004 Type Hierarchy Comp-303 : Programming Techniques Lecture 9 Alexandre Denault Computer Science McGill University Winter 2004 February 16, 2004 Lecture 9 Comp 303 : Programming Techniques Page 1 Last lecture...

More information

OO Design Principles

OO Design Principles OO Design Principles Software Architecture VO (706.706) Roman Kern Institute for Interactive Systems and Data Science, TU Graz 2018-10-10 Roman Kern (ISDS, TU Graz) OO Design Principles 2018-10-10 1 /

More information

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

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO

More information

Object-Oriented Design

Object-Oriented Design Object-Oriented Design Department of Computer Engineering Lecture 12: Object-Oriented Principles Sharif University of Technology 1 Open Closed Principle (OCP) Classes should be open for extension but closed

More information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

A Concept of Type Derivation for Object-Oriented Database Systems

A Concept of Type Derivation for Object-Oriented Database Systems in: L.Gün, R.Onvural, E.Gelenbe (eds.): Proc. 8 th International Symposium on Computer and Information Systems, Istanbul, 1993 A Concept of Type Derivation for Object-Oriented Database Systems Michael

More information

Object-Oriented Concepts and Design Principles

Object-Oriented Concepts and Design Principles Object-Oriented Concepts and Design Principles Signature Specifying an object operation or method involves declaring its name, the objects it takes as parameters and its return value. Known as an operation

More information

Call by Declaration. Erik Ernst 1. Dept. of Computer Science, University of Aarhus, Denmark

Call by Declaration. Erik Ernst 1. Dept. of Computer Science, University of Aarhus, Denmark Call by Declaration Erik Ernst 1 Dept. of Computer Science, University of Aarhus, Denmark eernst@daimi.au.dk Abstract. With traditional inheritance mechanisms, a subclass is able to use inherited features

More information

Pattern-Oriented Development with Rational Rose

Pattern-Oriented Development with Rational Rose Pattern-Oriented Development with Rational Rose Professor Peter Forbrig, Department of Computer Science, University of Rostock, Germany; Dr. Ralf Laemmel, Department of Information Management and Software

More information

Object-Oriented Genetic Improvement for Improved Energy Consumption in Google Guava

Object-Oriented Genetic Improvement for Improved Energy Consumption in Google Guava Object-Oriented Genetic Improvement for Improved Energy Consumption in Google Guava Nathan Burles 1, Edward Bowles 1, Alexander E. I. Brownlee 2, Zoltan A. Kocsis 2, Jerry Swan 1, Nadarajen Veerapen 2

More information

Idioms for Building Software Frameworks in AspectJ

Idioms for Building Software Frameworks in AspectJ Idioms for Building Software Frameworks in AspectJ Stefan Hanenberg 1 and Arno Schmidmeier 2 1 Institute for Computer Science University of Essen, 45117 Essen, Germany shanenbe@cs.uni-essen.de 2 AspectSoft,

More information

Inheritance. Transitivity

Inheritance. Transitivity Inheritance Classes can be organized in a hierarchical structure based on the concept of inheritance Inheritance The property that instances of a sub-class can access both data and behavior associated

More information

Inheritance and Substitution (Budd chapter 8, 10)

Inheritance and Substitution (Budd chapter 8, 10) Inheritance and Substitution (Budd chapter 8, 10) 1 2 Plan The meaning of inheritance The syntax used to describe inheritance and overriding The idea of substitution of a child class for a parent The various

More information

E-R Model. Hi! Here in this lecture we are going to discuss about the E-R Model.

E-R Model. Hi! Here in this lecture we are going to discuss about the E-R Model. E-R Model Hi! Here in this lecture we are going to discuss about the E-R Model. What is Entity-Relationship Model? The entity-relationship model is useful because, as we will soon see, it facilitates communication

More information

REVIEW OF THE BASIC CHARACTERISTICS OF OBJECT ORIENTATION

REVIEW OF THE BASIC CHARACTERISTICS OF OBJECT ORIENTATION c08classandmethoddesign.indd Page 282 13/12/14 2:57 PM user 282 Chapter 8 Class and Method Design acceptance of UML as a standard object notation, standardized approaches based on work of many object methodologists

More information

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java

More information

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

Atelier Java - J1. Marwan Burelle.  EPITA Première Année Cycle Ingénieur. marwan.burelle@lse.epita.fr http://wiki-prog.kh405.net Plan 1 2 Plan 3 4 Plan 1 2 3 4 A Bit of History JAVA was created in 1991 by James Gosling of SUN. The first public implementation (v1.0) in 1995.

More information

Exheritance Class Generalisation Revived

Exheritance Class Generalisation Revived Exheritance Class Generalisation Revived Markku Sakkinen Information Technology Research Institute University of Jyväskylä P.O.Box 35 (Agora) FIN-40351 Jyväskylä Finland sakkinenm@acm.org or sakkinen@cs.jyu.fi

More information

HOW AND WHEN TO FLATTEN JAVA CLASSES?

HOW AND WHEN TO FLATTEN JAVA CLASSES? HOW AND WHEN TO FLATTEN JAVA CLASSES? Jehad Al Dallal Department of Information Science, P.O. Box 5969, Safat 13060, Kuwait ABSTRACT Improving modularity and reusability are two key objectives in object-oriented

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

JOURNAL OF OBJECT TECHNOLOGY

JOURNAL OF OBJECT TECHNOLOGY JOURNAL OF OBJECT TECHNOLOGY Online at www.jot.fm. Published by ETH Zurich, Chair of Software Engineering JOT, 2002 Vol. 1, No. 2, July-August 2002 The Theory of Classification Part 2: The Scratch-Built

More information

EMBEDDED SYSTEMS PROGRAMMING OO Basics

EMBEDDED SYSTEMS PROGRAMMING OO Basics EMBEDDED SYSTEMS PROGRAMMING 2014-15 OO Basics CLASS, METHOD, OBJECT... Class: abstract description of a concept Object: concrete realization of a concept. An object is an instance of a class Members Method:

More information

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages Preliminaries II 1 Agenda Objects and classes Encapsulation and information hiding Documentation Packages Inheritance Polymorphism Implementation of inheritance in Java Abstract classes Interfaces Generics

More information

Object Orientation. Chapter Sixteen Modern Programming Languages, 2nd ed. 1

Object Orientation. Chapter Sixteen Modern Programming Languages, 2nd ed. 1 Object Orientation Chapter Sixteen Modern Programming Languages, 2nd ed. 1 Definitions Give definitions for the following: Object-oriented language Object-oriented programming Then again, why bother? Chapter

More information

Wrapping a complex C++ library for Eiffel. FINAL REPORT July 1 st, 2005

Wrapping a complex C++ library for Eiffel. FINAL REPORT July 1 st, 2005 Wrapping a complex C++ library for Eiffel FINAL REPORT July 1 st, 2005 Semester project Student: Supervising Assistant: Supervising Professor: Simon Reinhard simonrei@student.ethz.ch Bernd Schoeller Bertrand

More information

Concepts of Object-Oriented Programming Peter Müller

Concepts of Object-Oriented Programming Peter Müller Concepts of Object-Oriented Programming Peter Müller Chair of Programming Methodology Autumn Semester 2018 5. Information Hiding and Encapsulation 2 5. Information Hiding and Encapsulation 5.1 Information

More information

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

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in

More information

Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson

Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson January 13, 2005 January 18, 2005 1 of 38 Lecture Goals Introduce the basic concepts of object-oriented analysis/design/programming

More information

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

Inheritance and Substitution גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון Inheritance and Substitution גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap In this chapter we will start to investigate the concepts of inheritance and substitution: The intuitive and practical

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Coordination Patterns

Coordination Patterns Coordination Patterns 1. Coordination Patterns Design Patterns and their relevance for Coordination Oscar Nierstrasz Software Composition Group Institut für Informatik (IAM) Universität Bern oscar@iam.unibe.ch

More information

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

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc. Chapter 13 Object Oriented Programming Contents 13.1 Prelude: Abstract Data Types 13.2 The Object Model 13.4 Java 13.1 Prelude: Abstract Data Types Imperative programming paradigm Algorithms + Data Structures

More information

COS 320. Compiling Techniques

COS 320. Compiling Techniques Topic 5: Types COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Types: potential benefits (I) 2 For programmers: help to eliminate common programming mistakes, particularly

More information

A Short Summary of Javali

A Short Summary of Javali A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler

More information

Evaluation Issues in Generic Programming with Inheritance and Templates in C++

Evaluation Issues in Generic Programming with Inheritance and Templates in C++ Evaluation Issues in Generic Programming with Inheritance and Templates in C++ Emil Vassev, Joey Paquet Department of Computer Science and Software Engineering Concordia University Montreal, Quebec, H3G

More information

PROGRAMMING LANGUAGE 2

PROGRAMMING LANGUAGE 2 31/10/2013 Ebtsam Abd elhakam 1 PROGRAMMING LANGUAGE 2 Java lecture (7) Inheritance 31/10/2013 Ebtsam Abd elhakam 2 Inheritance Inheritance is one of the cornerstones of object-oriented programming. It

More information

OO Technology: Properties and Limitations for Component-Based Design

OO Technology: Properties and Limitations for Component-Based Design TDDD05 Component-Based Software OO Technology: Properties and Limitations for Component-Based Design Interfaces Design by by Contract Syntactic Substitutability Inheritance Considered Harmful Fragile Base

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

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

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes Inheritance Inheritance is the mechanism of deriving new class from old one, old class is knows as superclass and new class is known as subclass. The subclass inherits all of its instances variables and

More information

More About Objects. Zheng-Liang Lu Java Programming 255 / 282

More About Objects. Zheng-Liang Lu Java Programming 255 / 282 More About Objects Inheritance: passing down states and behaviors from the parents to their children. Interfaces: requiring objects for the demanding methods which are exposed to the outside world. Polymorphism

More information

22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini 22. Inheritance Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Superclasses and Subclasses Using the super Keyword Overriding Methods The Object Class References Inheritance Object-oriented programming

More information

Module 10 Inheritance, Virtual Functions, and Polymorphism

Module 10 Inheritance, Virtual Functions, and Polymorphism Module 10 Inheritance, Virtual Functions, and Polymorphism Table of Contents CRITICAL SKILL 10.1: Inheritance Fundamentals... 2 CRITICAL SKILL 10.2: Base Class Access Control... 7 CRITICAL SKILL 10.3:

More information

Inheritance, Polymorphism, and Interfaces

Inheritance, Polymorphism, and Interfaces Inheritance, Polymorphism, and Interfaces Chapter 8 Inheritance Basics (ch.8 idea) Inheritance allows programmer to define a general superclass with certain properties (methods, fields/member variables)

More information

Pattern Examples Behavioural

Pattern Examples Behavioural Pattern Examples Behavioural based on patterns in Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides, Design Patterns, Addison-Wesley, 1995. ISBN 0-201-63361-2 PE2-1 Iterator Pattern Intent» Access

More information

C++ Programming: Polymorphism

C++ Programming: Polymorphism C++ Programming: Polymorphism 2018 년도 2 학기 Instructor: Young-guk Ha Dept. of Computer Science & Engineering Contents Run-time binding in C++ Abstract base classes Run-time type identification 2 Function

More information

Some Notes on Generics in C#

Some Notes on Generics in C# Some Notes on Generics in C# Janusz Jabłonowski Abstract: Generics allow programmers to write more abstract code, which is - to some degree - independent from the types involved in the underlying algorithm.

More information

Chapter 2 Overview of the Design Methodology

Chapter 2 Overview of the Design Methodology Chapter 2 Overview of the Design Methodology This chapter presents an overview of the design methodology which is developed in this thesis, by identifying global abstraction levels at which a distributed

More information

Inheritance and object compatibility

Inheritance and object compatibility Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not the other way around Examples: reference/pointer can

More information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

10. Object-oriented Programming. 7. Juli 2011

10. Object-oriented Programming. 7. Juli 2011 7. Juli 2011 Einführung in die Programmierung Introduction to C/C++, Tobias Weinzierl page 1 of 47 Outline Object Case Study Brain Teaser Copy Constructor & Operators Object-oriented Programming, i.e.

More information

CMSC 132: Object-Oriented Programming II

CMSC 132: Object-Oriented Programming II CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation

More information

When Java technology burst onto the Internet scene in 1995,

When Java technology burst onto the Internet scene in 1995, MOBILE CODE SECURITY SECURE JAVA CLASS LOADING The class loading mechanism, LI GONG Sun Microsystems central to Java, plays a key role in JDK 1.2 by enabling When Java technology burst onto the Internet

More information

Lists. Michael P. Fourman. February 2, 2010

Lists. Michael P. Fourman. February 2, 2010 Lists Michael P. Fourman February 2, 2010 1 Introduction The list is a fundamental datatype in most functional languages. ML is no exception; list is a built-in ML type constructor. However, to introduce

More information

Object Oriented Paradigm

Object Oriented Paradigm Object Oriented Paradigm History Simula 67 A Simulation Language 1967 (Algol 60 based) Smalltalk OO Language 1972 (1 st version) 1980 (standard) Background Ideas Record + code OBJECT (attributes + methods)

More information

CS-202 Introduction to Object Oriented Programming

CS-202 Introduction to Object Oriented Programming CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction

More information

CS112 Lecture: Defining Instantiable Classes

CS112 Lecture: Defining Instantiable Classes CS112 Lecture: Defining Instantiable Classes Last revised 2/3/05 Objectives: 1. To describe the process of defining an instantiable class 2. To discuss public and private visibility modifiers. Materials:

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 6 : Abstraction Lecture Contents 2 Abstract classes Abstract methods Case study: Polymorphic processing Sealed methods & classes

More information

Chief Reader Report on Student Responses:

Chief Reader Report on Student Responses: Chief Reader Report on Student Responses: 2017 AP Computer Science A Free-Response Questions Number of Students Scored 60,519 Number of Readers 308 Score Distribution Exam Score N %At Global Mean 3.15

More information

24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini 24. Inheritance Java Fall 2009 Instructor: Dr. Masoud Yaghini Outline Superclasses and Subclasses Using the super Keyword Overriding Methods The Object Class References Superclasses and Subclasses Inheritance

More information

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides 1B1b Inheritance Agenda Introduction to inheritance. How Java supports inheritance. Inheritance is a key feature of object-oriented oriented programming. 1 2 Inheritance Models the kind-of or specialisation-of

More information

22. Subtyping, Inheritance and Polymorphism

22. Subtyping, Inheritance and Polymorphism 741 Last Week: ression Trees 742 22. Subtyping, Inheritance and Polymorphism ression Trees, Separation of Concerns and Modularisation, Type Hierarchies, Virtual Functions, Dynamic Binding, Code Reuse,

More information

The Design of Core C++ (Notes)

The Design of Core C++ (Notes) The Design of Core C++ (Notes) Uday Reddy May 13, 1994 This note is to define a small formal language called Core C++ which reflects the essential structure of C++. As the name implies, the design only

More information