Late-bound Pragmatical Class Methods

Size: px
Start display at page:

Download "Late-bound Pragmatical Class Methods"

Transcription

1 Late-bound Pragmatical Class Methods AXEL SCHMOLITZKY, MARK EVERED, J. LESLIE KEEDY, GISELA MENGER Department of Computer Structures University of Ulm Ulm, Germany {axel, markev, keedy, Abstract Binary methods are one of the challenges for designers of object-oriented programming languages. In this paper we discuss binary class methods (class methods that receive parameters of their own class type) as an alternative for typical uses of binary instances methods and show that they are often less troublesome, more symmetrical and more expressive. However, the main drawback of class methods as they are defined in languages like C++ and Java is that their static binding excludes them from being used in certain codereuse scenarios that need late-bound selfreference. We propose a small and surprisingly simple language mechanism to overcome this drawback. This mechanism can easily be adopted by languages that offer statically bound class methods. We further give the semantics of this extension as a mapping onto an object model without class methods. 1 Introduction A binary method, as defined in [Bru95], is an instance method of some object of type τ that has a parameter of the same type τ. Binary methods are (still) one of the challenges for designers of object-oriented programming languages as is well discussed in that paper. They can be seen as a focus demonstrating the difficulty of combining three partly competing goals of modern objectoriented languages: static type safety encapsulation flexibility in code reuse In this paper we discuss binary pragmatical class methods as an alternative for typical uses of binary methods (which will be referred to as binary instance methods for better distinction). In analogy to the definition of a binary instance method we define a binary class method as a class method of some class defining type τ that has at least one parameter of this type τ. As with binary instance methods, this definition does not exclude further parameters, and the typical case of a binary class method is indeed a method with two parameters of type τ. We first show that binary pragmatical class methods are often more appropriate and less troublesome than binary instance methods. We

2 further show that one of the defining qualities of pragmatical class methods their static binding is a logical property that is useful for extending their expressability but that need not imply that they have to be statically bound in their implementation. Throughout the paper we use the Java Programming Language [GJS96] as the language for demonstration, but the results in this paper apply equally to other object-oriented languages. Before we can start the discussion we must define the term pragmatical class method. 2 Pragmatical class methods It may seem obvious what is meant by a class method but if we take a closer look we must differentiate several distinct properties. What are the defining properties of a class method? First of all class methods clearly appear only in languages that directly support a notion of a class. Thus we can narrow the discussion to class-based languages like Smalltalk [GoR89], C++ [ElS90], Eiffel [Mey92], and Java. The exact status of a class differs between these languages, however. In Smalltalk classes are instances of meta classes and thus are not special in respect to their methods; class methods are simply instance methods of a meta class instance. In Eiffel classes are only a compile-time notion that completely disappears at run-time; thus class methods simply do not exist in the language model. In C++ and Java a compromise is made; there exists a notion of a class object that can be manipulated at runtime, but this object is statically defined. Thus class methods can be statically bound in these languages. The language models of Smalltalk and Eiffel can be seen as more consistent either fully accept classes as objects, treat them as first-class citizens and naturally support class methods, or fully neglect classes at run-time and by this keep the principle that every invocation at run-time is an invocation of a first-class object. In the following we refer to the pragmatical view of class methods in C++ and Java by calling them pragmatical class methods. Although such pragmatical class method do not neatly fit into regular object models they are well accepted in practice as is shown by the decision of the designers of Java to adopt the concept from C++. What then are the defining properties of a pragmatical class method? We formulate them as follows: Class Bound: A pragmatical class method belongs to a class and is part of the class definition. This implies for example that a class method is inherited if the class it belongs to is inherited. Full Access: Pragmatical class method have access to the private fields and methods of the class. This can be concluded from the Class Bound property and is especially relevant for the efficient implementation of binary operations. Static Binding: A pragmatical class method is statically bound. This means that the language entity a class method invocation is qualified with is assumed to be a static reference. No Self: Inside the body of a pragmatical class method no reference to 'self' is allowed. 2

3 Only the last two properties distinguish a pragmatical class method from an instance method. The aim of this paper is to show that the Static Binding property can partly be relaxed to make pragmatical class methods even more valuable than they already are. Before we discuss this point, however, we first demonstrate the value of binary pragmatical class methods in comparison to binary instance methods. In the following we refer to pragmatical class methods simply with the term class method. 3 Binary class methods versus binary instance methods In this section we discuss binary class methods as an alternative to binary instance methods. We compare them by using both kinds of methods to model binary operations. A binary operation shall be understood as an abstract operation on an abstract object type that involves two instances of that type. For example, the abstract binary operation comparison for equality on objects of a type T can be modeled either as the binary instance method boolean equals(t other) of a class T 1 or as the binary class method boolean equal(t o1, T o2) of a class T 2, with both T 1 and T 2 implementing T. We compare three possibilities for modeling a binary operation that tests two instances for equality. These instances are either instances of a Point class or of a ColorPoint class. Instances of the Point class represent two-dimensional cartesian points. Instances of the ColorPoint class represent colored points, i.e. two-dimensional cartesian points with an additional color property. Equality for points shall be defined as equality of the coordinates, whereas equality for colored points shall be defined as equality of the coordinates and equality of the color property. In our scenario we are particularly interested in the possibility of comparing colored points just for point equality. Similar practical programming examples are comparing two lists for equality as bags (i.e. without respect to their ordering) and comparing two employee objects for equality as persons (i.e. is it the same person employed in two different ways), In all of the following Java modelings the representation of an object of class Point is encapsulated by access methods to its logical components, namely its x- and y-coordinate. These are modeled as private instance fields called rep_x and rep_y, respectively. The class ColorPoint additionally defines access methods to a private color field called rep_color. Class Point defines a constructor with two parameters, giving initial values for the coordinates. Class ColorPoint defines a constructor with three parameters, giving initial values for the coordinates and the color. All parameters are of type int for simplicity. Modeling 1: instance methods with overriding In the first modeling the equality operation for two points is implemented in the Java-conformant style by overriding the binary instance method equals of class Object. Class ColorPoint inherits from Point and again overrides method equals with an implementation that compares two instances of ColorPoint. 3

4 class Point { // modeling 1 public boolean equals (Object other) { if (other instanceof Point) { Point p = (Point)other; return (this.rep_x == p.rep_x) && (this.rep_y == p.rep_y); else return false; class ColorPoint extends Point { public boolean equals (Object other) { if (other instanceof ColorPoint) { ColorPoint c = (ColorPoint)other; return (super.equals(other)) && (this.rep_color == c.rep_color); else return false; This is the approach encouraged by the Java style but it has two drawbacks. The first (minor) is efficiency: The instanceof test and the cast both incur run-time checks, which are necessary because the parameter has a generic type. The second drawback is more problematic. It is not possible to compare two ColorPoint instances only for the equality of their coordinates, i.e. use the code of the equals method in Point for the comparison. This problem can be solved if we define binary instance methods with overloading instead of overriding. Modeling 2: instance methods with overloading In the second modeling the test for equality in class Point is implemented as a real binary instance method, i.e. an instance method that is passed a parameter of type Point. class Point { // modeling 2.1 public boolean equals (Point other) { return (this.rep_x == other.rep_x) && (this.rep_y == other.rep_y); The implementation for equals (method 1 in the following) can in this case be sure that it is passed a Point instance and can directly manipulate the internal representation. No runtime checks are needed. Class ColorPoint inherits from this version of Point and provides its own binary instance method (method 2) for testing the equality of colored points. class ColorPoint extends Point { // 2.2 public boolean equals (ColorPoint other) { return (super.equals(other)) && (this.rep_color == other.rep_color); With this modeling equals is statically overloaded in ColorPoint and thus ColorPoint has two equals methods 1. Method 1 is inherited from Point and has a formal parameter of type Point. Method 2 is provided directly with a formal parameter of type ColorPoint and thus can access the internal color field of its argument unconditionally. Again no runtime overhead is incurred. If we now assume the declarations Point p1 = new Point(1,1); Point p2 = new Point(0,0); ColorPoint c1 = new ColorPoint(1,1,1); ColorPoint c2 = new ColorPoint(1,1,0); then the following expressions will behave like this: p1.equals(p2) // method 1 false p1.equals(c1) // method 1 true c1.equals(p1) // inherited method 1 true c1.equals(c2) // method 2 false 1 In fact, in Java it has three equals methods, but in this discussion we can ignore the one from class Object. 4

5 Note that in none of these cases the dynamic type of the called object influences the semantics of the call, because no method is overridden. With this modeling it is possible to test whether two ColorPoint instances only have the same coordinates. This can be done by forcing the compiler to statically choose the first equals method. One way is to pass an argument of static type Point. // passing a ColorPoint as a Point c1.equals((point)c2) // inherited method 1 // true In this case the compiler has the choice between two methods, because the interface of ColorPoint offers two equals signatures. But only one of these allows an argument of static type Point and is thus chosen. Again the dynamic dispatch at runtime just causes the inherited code of method 1 to be called. Another way to achieve the same is to make the call to c1 via a variable of type Point. // calling a ColorPoint as a Point ((Point)c1).equals(c2) // method 1 true Here the fact is used that a call of the equals method of a variable of type Point is statically determined to mean the only equals signature Point offers, namely the one that expects an argument of type Point. The subtyping rules allow us to pass a variable of type ColorPoint. The dynamic dispatch at runtime then just causes the inherited code of method 1 to be called. Both solutions are rather cumbersome and detract from the readability of the source. One might prefer to have a way of directly saying "now call the Point equals method for these two ColorPoint variables". Modeling 3: class methods with overloading This can be achieved by modeling the comparison operations with binary class methods (which we name equal instead of equals). class Point { // modeling 3 (Point p1, Point p2) { return (p1.rep_x == p2.rep_x) && (p1.rep_y == p2.rep_y); class ColorPoint extends Point { (ColorPoint p1, ColorPoint p2) { return (Point.equal(p1,p2)) && (p1.rep_color == p2.rep_color); With this modeling it is straightforward to compare two ColorPoint variables for the equality of their coordinates: Point.equal(c1,c2) The other expressions from above are also more readable with binary class methods: Point.equal(p1,p2) Point.equal(p1,c1) Point.equal(c1,p1) ColorPoint.equal(c1,c2) Overall this modeling better reflects the fact that the two equal methods are semantically different operations. However, this modeling has a minor drawback. Class ColorPoint has two equal methods in its interface, one inherited with Point parameters, the other directly provided with ColorPoint parameters. The former is even less useful than the inherited equals method in modeling 2, which at least made it possible to pass a Point 5

6 variable to an equals method of a ColorPoint variable. We come back to this in section 4. Other arguments for class methods A further advantage of binary class methods (or class methods in general) is that they can better handle exceptional cases. If in an invocation of a binary instance method the receiver is a null reference the call will fail, although the comparison with a null reference could be welldefined in an application. Binary class methods are in general preferable to binary instance methods for symmetrical operations like the comparison for equality, where two or more objects of the same type are treated 'on equal terms'. These seem to constitute most applications of binary instance methods in practice. To model such operations with binary instance methods is an asymmetrical preference of one argument that is hard to justify. 4 Pragmatical class methods allow covariance We have defined that pragmatical class methods are statically bound. Although this property can restrict flexibility (see next section) it can also be seen as an advantage. We demonstrate this by informally introducing a language extension. We motivate this extension by recalling the drawback from modeling 3, the useless equal method in ColorPoint. This unnecessary duplication could be avoided by the use of the type identifier ThisType for typing the parameters of equal, which would imply a covariant adaptation of the parameter types. Informally, for type checking ThisType automatically adapts to the type of the class it is defined in. Such constructs have been extensively discussed for instance methods but not for class methods. Modeling 4: class methods with ThisType and hiding By typing the parameters of class method equal with ThisType we get the following: class Point { // modeling 4 return (p1.rep_x == p2.rep_x) && (p1.rep_y == p2.rep_y); class ColorPoint extends Point { (ThisType p1,thistype p2) { return (Point.equal(p1,p2)) && (p1.rep_color == p2.rep_color); We define this modeling to mean that the equal method in ColorPoint hides the equal method from Point (as it is defined for class methods with identical signatures in Java). The effect then would be that both Point and ColorPoint offer just one equal method in their interface. The interesting point is that such a covariant adaptation does not result in the well known subtyping problems with binary instance methods. This is due to the fact that class methods are not dynamically dispatched (Static Binding property). It follows that ColorPoint can still be seen as a subtype of Point and we can still compare ColorPoint instances for Point equality in a straightforward way. It is well known that the introduction of a flexible type identifier like ThisType is not as easy as it 6

7 may seem here. In order to avoid recompilation or repeated type checking on code-reuse, certain restrictions must be placed on code that contains ThisType (for example no assignment of a Point expression to a ThisType variable). Such restrictions are discussed for example for matching [BSG95]. What about matching anyway? At this point it is interesting to see how matching is related to this discussion. Matching is a relation between classes very similar to the subtype relation but allowing covariant parameter type changes in instance methods via ThisType. If we again assume that Java were extended by ThisType, the Point/ColorPoint example could look like this: class Point { public boolean equals (ThisType other) { return (this.rep_x == other.rep_x) && (this.rep_y == other.rep_y); class ColorPoint extends Point { public boolean equals (ThisType other) { return (super.equals(other)) && (this.rep_color == other.rep_color); With this modeling equals in ColorPoint overrides the inherited method, as in modeling 1. But matching is a generalization of subtyping, and especially in this case the covariant change of parameter type excludes subtyping. But if ColorPoint is not a subtype of Point it is not possible to pass a ColorPoint object to a method that expects a Point parameter. This means that matching doesn't help with the situation we want to express, to call the Point equals methods for two ColorPoint variables. 5 Dependencies between class methods Given that binary class methods are often more readable and more expressive than binary instance methods in subtype relationships, we now turn to the question of code-reuse. As we will see, the Static Binding property which allows statically type-safe covariant parameters can lead to inflexibility in code-reuse. Sometimes operations are defined in terms of other operations. Assume the simple case that the binary operation equalandvisible for two points is defined as returning true if the equal operation returns true and both points are visible (an additional attribute), and otherwise returning false. This could be modeled with binary class methods as follows: class Point { AndVisible if (equal(p1,p2)) { In this example the class method invocation of equal in equalandvisible is not qualified which means that it is implicitly qualified with the class name it is defined in: if (Point.equal(p1,p2)) { For colored points the operation equalandvisible could also be defined on the basis of equal, but here on the basis of equal for colored points. If we model this with a class inheriting from Point and hiding equal: 7

8 class ColorPoint extends Point { // new implementation of equal Then the fact that pragmatical class methods are statically bound implies that in the inherited code of equalandvisible the equal method from Point is still called. The only way to work around this would be to reimplement equalandvisible as well. It would be nice if it were possible to define the equalandvisible method on the basis of the equal method in the current class. If both binary operations were modeled with binary instance methods this relationship would be defined implicitly. A language extension An appropriate language mechanism to express such a relation also between class methods could look like this: class Point { AndVisible if (ThisType.equal(p1,p2)) { The informal semantics of this mechanism is that the class method of the current class is called. If this mechanism were provided in a language like Java, class methods would gain a great deal of flexibility with respect to code-reuse. In combination with covariance many typical binary operations could be modeled very elegantly with pragmatical class methods. For Java, for example, a binary covariant class method equal with two parameters of type ThisType could be defined in class Object. Just like the binary instance method equals it could by default be implemented as a test for reference equality, but be hidden in subclasses that want to define equality differently. The advantage would be that its parameter typing would adapt to the type of the inheriting class. 6 Semantics of late-bound pragmatical class methods It is obvious that pragmatical class methods can not be statically bound if the mechanism of the last section is provided. We thus have to claim pragmatical class methods to be late-bound. On the other hand we don t want to lose the defining property of pragmatical class methods their Static Binding because it is the precondition that pragmatical class methods can allow covariance of their argument types. In this section we define a semantics of late-bound pragmatical class methods that integrates both requirements. Mapping to instance methods We define the semantics of a class method invocation as a mapping onto an instance method invocation. This mapping is straightforward for any object-oriented language and thus allows us to integrate pragmatical class methods even into languages that do not offer class methods at all (like Eiffel). A prerequisite is that class method declarations are mapped onto instance method declarations. 8

9 Mapping declarations DeclMap: For any class method cm the class declaration class C { static <return type> cm ( <args> ) { <statements> is mapped onto class C { <return type> cm ( <args> ) { <statements> The mappings of class method invocations are equally simple. Mapping invocations Three cases have to be considered: class method invocations qualified with a class name, class method invocations qualified with ThisType and unqualified class method invocations. InvocMap1: For any class C declaring class method cm a class method invocation of the form C.cm( <args> ); is mapped onto (new C()).cm(<args>); InvocMap2: Any class method invocation of a class method cm of the form ThisType.cm(<args>); is mapped onto cm(<args>); InvocMap3: For any class C declaring class method cm a class method invocation of the form cm(<args>); is mapped onto (new C()).cm (<args>); Comments The class method invocations in InvocMap2 and InvocMap3 can only appear inside a class C declaring cm. InvocMap2 implies that an invocation via ThisType is mapped onto an invocation via this, which will always be valid. Either the invocation appears in an instance method of C and this must have a defined value; or the invocation appears in a class method that, due to DeclMap, is mapped onto an instance method. InvocMap3 means that an unqualified class method invocation is assumed to be equivalent to a class method invocation that is explicitly qualified with a class name. This reflects the interpretation of unqualified class method invocations in Java. Alternatively, unqualified invocations could be mapped like class method invocations that are explicitly qualified with ThisType. This would more consistently mirror the interpretation of unqualified instance method invocations. With our definition we preferred compatibility over consistency. Realization The semantics we have defined are straightforward and could be directly implemented. In the code resulting from InvocMap1 and InvocMap3 the newly created instance is just a dummy instance. Because instance creation is typically expensive and might be more complicated (for example because of constructor parameters) this dummy instance should preferably be created at system startup and provided with each call. Note that this dummy 9

10 instance can be seen as an instance representing the class object. We regard the extra indirection required for a late-bound call in comparison to a staticallybound call as being insignificant in the overall cost of invoking a method. Pragmatical class methods refined In view of these semantics, we must refine the third of the defining properties of pragmatical class methods from section 2 (changes are given in italics): Static Binding: A pragmatical class method is logically statically bound for clients of a class. This means that for a client the language entity a class method invocation is qualified with is assumed to be a logically static reference. From a clients point of view a pragmatical class method is a method that is statically bound. Thus a client knows exactly which code is being invoked the code of the class the class method is invoked on. Although this is what a programmer sometimes wants, it need not mean that pragmatical class methods must be statically bound in their implementation. 7 Summary In this paper we have discussed pragmatical class methods as a useful concept in object-oriented programming languages. First we have shown that in some situations binary class methods have advantages over binary instance methods in terms of readability, expressability and symmetry. In particular, pragmatical binary class methods allow covariant parameter type adaptation without paying the price of losing the subtype relation between classes, as is the case with binary instance methods and matching. As the main contribution we have shown that a simple language extension can eliminate the inflexibility of pragmatical class methods for code-reuse. We defined the semantics of this extension with a simple mapping onto a language model that need only provide instance methods. Our extension and its semantics are so simple that the extension could easily be integrated into existing languages. Besides a minor loss in efficiency we can see no reason why pragmatical class methods in future languages should not be defined in this way. References [Bru95] Bruce, K. B., et al.: On Binary Methods, Theory and Practice of Object Systems, 1:3, S , [BSG95] Bruce, K. B., Schuett, A., Gent, R. v.: PolyTOIL: A Type-Safe Polymorphic Object- Oriented Language, Proc. ECOOP '95, Aarhus, Denmark; in Lecture Notes in Computer Science 952, Springer-Verlag, [ElS90] Ellis, M. A., Stroustrup, B.: The Annotated C++ Reference Manual, Addison- Wesley, Reading, MA, [GoR89] Goldberg, A., Robson, D.: Smalltalk-80: The Language, Addison-Wesley, Reading, MA, [GJS96] Gosling, J., Joy, B., Steele, G.: The Java Language Specification, Addison-Wesley, Reading, MA, [Mey92] Meyer, B.: Eiffel: the Language, Prentice-Hall, New York,

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

Object Oriented Programming. Java-Lecture 11 Polymorphism

Object Oriented Programming. Java-Lecture 11 Polymorphism Object Oriented Programming Java-Lecture 11 Polymorphism Abstract Classes and Methods There will be a situation where you want to develop a design of a class which is common to many classes. Abstract class

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

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

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

The Java Programming Language

The Java Programming Language The Java Programming Language Slide by John Mitchell (http://www.stanford.edu/class/cs242/slides/) Outline Language Overview History and design goals Classes and Inheritance Object features Encapsulation

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

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

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

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

What is Inheritance?

What is Inheritance? Inheritance 1 Agenda What is and Why Inheritance? How to derive a sub-class? Object class Constructor calling chain super keyword Overriding methods (most important) Hiding methods Hiding fields Type casting

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

Java: introduction to object-oriented features

Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer

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

Subtyping. Lecture 13 CS 565 3/27/06

Subtyping. Lecture 13 CS 565 3/27/06 Subtyping Lecture 13 CS 565 3/27/06 Polymorphism Different varieties of polymorphism: Parametric (ML) type variables are abstract, and used to encode the fact that the same term can be used in many different

More information

Inheritance (Chapter 7)

Inheritance (Chapter 7) Inheritance (Chapter 7) Prof. Dr. Wolfgang Pree Department of Computer Science University of Salzburg cs.uni-salzburg.at Inheritance the soup of the day?! Inheritance combines three aspects: inheritance

More information

Comp 311 Principles of Programming Languages Lecture 21 Semantics of OO Languages. Corky Cartwright Mathias Ricken October 20, 2010

Comp 311 Principles of Programming Languages Lecture 21 Semantics of OO Languages. Corky Cartwright Mathias Ricken October 20, 2010 Comp 311 Principles of Programming Languages Lecture 21 Semantics of OO Languages Corky Cartwright Mathias Ricken October 20, 2010 Overview I In OO languages, data values (except for designated non-oo

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

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

CS558 Programming Languages Winter 2013 Lecture 8

CS558 Programming Languages Winter 2013 Lecture 8 OBJECT-ORIENTED PROGRAMMING CS558 Programming Languages Winter 2013 Lecture 8 Object-oriented programs are structured in terms of objects: collections of variables ( fields ) and functions ( methods ).

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

Data Abstraction. Hwansoo Han

Data Abstraction. Hwansoo Han Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed

More information

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Design issues for objectoriented. languages. Objects-only pure language vs mixed. Are subclasses subtypes of the superclass? Encapsulation Encapsulation grouping of subprograms and the data they manipulate Information hiding abstract data types type definition is hidden from the user variables of the type can be declared variables

More information

CS-XXX: Graduate Programming Languages. Lecture 22 Class-Based Object-Oriented Programming. Dan Grossman 2012

CS-XXX: Graduate Programming Languages. Lecture 22 Class-Based Object-Oriented Programming. Dan Grossman 2012 CS-XXX: Graduate Programming Languages Lecture 22 Class-Based Object-Oriented Programming Dan Grossman 2012 PL Issues for OOP? OOP lets you: 1. Build some extensible software concisely 2. Exploit an intuitive

More information

Object-Oriented Programming

Object-Oriented Programming 13 Object-Oriented Programming Exercises 13.1 Using Java as an example: 13.2 Code reuse: inhertiance, interfaces. In the case of an interface, any class implementing the Comparable interface can be sorted

More information

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

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

Chapter 4 Defining Classes I

Chapter 4 Defining Classes I Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the

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

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

Data Structures (list, dictionary, tuples, sets, strings)

Data Structures (list, dictionary, tuples, sets, strings) Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access

More information

CS153: Compilers Lecture 11: Compiling Objects

CS153: Compilers Lecture 11: Compiling Objects CS153: Compilers Lecture 11: Compiling Objects Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 3 due today Project 4 out Due Thursday Oct 25 (16 days) Project 5 released

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

Inheritance. Unit 8. Summary. 8.1 Inheritance. 8.2 Inheritance: example. Inheritance Overriding of methods and polymorphism The class Object

Inheritance. Unit 8. Summary. 8.1 Inheritance. 8.2 Inheritance: example. Inheritance Overriding of methods and polymorphism The class Object Unit 8 Inheritance Summary Inheritance Overriding of methods and polymorphism The class Object 8.1 Inheritance Inheritance in object-oriented languages consists in the possibility of defining a class that

More information

Today s lecture. CS 314 fall 01 C++ 1, page 1

Today s lecture. CS 314 fall 01 C++ 1, page 1 Today s lecture Midterm Thursday, October 25, 6:10-7:30pm general information, conflicts Object oriented programming Abstract data types (ADT) Object oriented design C++ classes CS 314 fall 01 C++ 1, page

More information

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017 Overview of OOP Dr. Zhang COSC 1436 Summer, 2017 7/18/2017 Review Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in square brackets: l = [1, 2, "a"] (access by index, is mutable

More information

Class, Variable, Constructor, Object, Method Questions

Class, Variable, Constructor, Object, Method Questions Class, Variable, Constructor, Object, Method Questions http://www.wideskills.com/java-interview-questions/java-classes-andobjects-interview-questions https://www.careerride.com/java-objects-classes-methods.aspx

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

Implementing Software Connectors through First-Class Methods

Implementing Software Connectors through First-Class Methods Implementing Software Connectors through First-Class Methods Cheoljoo Jeong and Sangduck Lee Computer & Software Technology Laboratory Electronics and Telecommunications Research Institute Taejon, 305-350,

More information

Practice for Chapter 11

Practice for Chapter 11 Practice for Chapter 11 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Object-oriented programming allows you to derive new classes from existing

More information

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information

More information

CS152: Programming Languages. Lecture 23 Advanced Concepts in Object-Oriented Programming. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 23 Advanced Concepts in Object-Oriented Programming. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 23 Advanced Concepts in Object-Oriented Programming Dan Grossman Spring 2011 So far... The difference between OOP and records of functions with shared private state

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

Object-oriented Programming. Object-oriented Programming

Object-oriented Programming. Object-oriented Programming 2014-06-13 Object-oriented Programming Object-oriented Programming 2014-06-13 Object-oriented Programming 1 Object-oriented Languages object-based: language that supports objects class-based: language

More information

Subtyping (Dynamic Polymorphism)

Subtyping (Dynamic Polymorphism) Fall 2018 Subtyping (Dynamic Polymorphism) Yu Zhang Course web site: http://staff.ustc.edu.cn/~yuzhang/tpl References PFPL - Chapter 24 Structural Subtyping - Chapter 27 Inheritance TAPL (pdf) - Chapter

More information

CS260 Intro to Java & Android 03.Java Language Basics

CS260 Intro to Java & Android 03.Java Language Basics 03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance

More information

OBJECT ORİENTATİON ENCAPSULATİON

OBJECT ORİENTATİON ENCAPSULATİON OBJECT ORİENTATİON Software development can be seen as a modeling activity. The first step in the software development is the modeling of the problem we are trying to solve and building the conceptual

More information

Chapter 10 :: Data Abstraction and Object Orientation

Chapter 10 :: Data Abstraction and Object Orientation Chapter 10 :: Data Abstraction and Object Orientation Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright 2016 Elsevier Chapter10_Data_Abstraction_and_Object_Orientation_4e 1 Object-Oriented

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

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and

More information

BBM 102 Introduction to Programming II Spring Inheritance

BBM 102 Introduction to Programming II Spring Inheritance BBM 102 Introduction to Programming II Spring 2018 Inheritance 1 Today Inheritance Notion of subclasses and superclasses protected members UML Class Diagrams for inheritance 2 Inheritance A form of software

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

Conformance. Object-Oriented Programming Spring 2015

Conformance. Object-Oriented Programming Spring 2015 Conformance Object-Oriented Programming 236703 Spring 2015 1 What s Conformance? Overriding: replace method body in sub-class Polymorphism: subclass is usable wherever superclass is usable Dynamic Binding:

More information

CS-XXX: Graduate Programming Languages. Lecture 23 Types for OOP; Static Overloading and Multimethods. Dan Grossman 2012

CS-XXX: Graduate Programming Languages. Lecture 23 Types for OOP; Static Overloading and Multimethods. Dan Grossman 2012 CS-XXX: Graduate Programming Languages Lecture 23 Types for OOP; Static Overloading and Multimethods Dan Grossman 2012 So far... Last lecture (among other things): The difference between OOP and records

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

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

Computer Science 225 Advanced Programming Siena College Spring Topic Notes: Inheritance

Computer Science 225 Advanced Programming Siena College Spring Topic Notes: Inheritance Computer Science 225 Advanced Programming Siena College Spring 2017 Topic Notes: Inheritance Our next topic is another that is fundamental to object-oriented design: inheritance. Inheritance allows a programmer

More information

Grade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline

Grade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline Grade Weights Language Design and Overview of COOL CS143 Lecture 2 Project 0% I, II 10% each III, IV 1% each Midterm 1% Final 2% Written Assignments 10% 2.% each Prof. Aiken CS 143 Lecture 2 1 Prof. Aiken

More information

Universe Type System for Eiffel. Annetta Schaad

Universe Type System for Eiffel. Annetta Schaad Universe Type System for Eiffel Annetta Schaad Semester Project Report Software Component Technology Group Department of Computer Science ETH Zurich http://sct.inf.ethz.ch/ SS 2006 Supervised by: Dipl.-Ing.

More information

Field Analysis. Last time Exploit encapsulation to improve memory system performance

Field Analysis. Last time Exploit encapsulation to improve memory system performance Field Analysis Last time Exploit encapsulation to improve memory system performance This time Exploit encapsulation to simplify analysis Two uses of field analysis Escape analysis Object inlining April

More information

Object typing and subtypes

Object typing and subtypes CS 242 2012 Object typing and subtypes Reading Chapter 10, section 10.2.3 Chapter 11, sections 11.3.2 and 11.7 Chapter 12, section 12.4 Chapter 13, section 13.3 Subtyping and Inheritance Interface The

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

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Table of Contents 1 Reusing Classes... 2 1.1 Composition... 2 1.2 Inheritance... 4 1.2.1 Extending Classes... 5 1.2.2 Method Overriding... 7 1.2.3

More information

Comp 248 Introduction to Programming Chapter 4 & 5 Defining Classes Part B

Comp 248 Introduction to Programming Chapter 4 & 5 Defining Classes Part B Comp 248 Introduction to Programming Chapter 4 & 5 Defining Classes Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal, Canada These slides has

More information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass

More information

Chapter 9 :: Data Abstraction and Object Orientation

Chapter 9 :: Data Abstraction and Object Orientation Chapter 9 :: Data Abstraction and Object Orientation Programming Language Pragmatics Michael L. Scott Control or PROCESS abstraction is a very old idea (subroutines!), though few languages provide it in

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures Chapter 5: Procedural abstraction Proper procedures and function procedures Abstraction in programming enables distinction: What a program unit does How a program unit works This enables separation of

More information

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

More information

4 CoffeeStrainer Virtues and Limitations

4 CoffeeStrainer Virtues and Limitations In this chapter, we explain CoffeeStrainer s virtues and limitations and the design decisions that led to them. To illustrate the points we want to make, we contrast CoffeeStrainer with a hypothetical,

More information

Java Design Goals. Lecture 32: Java. Java Original implementations slow! Exceptions & Subtyping. - void method readfiles() throws IOException {...}!

Java Design Goals. Lecture 32: Java. Java Original implementations slow! Exceptions & Subtyping. - void method readfiles() throws IOException {...}! Java Design Goals Lecture 32: Java CSC 131 Fall, 2014 Kim Bruce Portability across platforms Reliability Safety (no viruses) Dynamic Linking Multithreaded execution Simplicity and Familiarity Efficiency

More information

Review: Object Diagrams for Inheritance. Type Conformance. Inheritance Structures. Car. Vehicle. Truck. Vehicle. conforms to Object

Review: Object Diagrams for Inheritance. Type Conformance. Inheritance Structures. Car. Vehicle. Truck. Vehicle. conforms to Object Review: Diagrams for Inheritance - String makemodel - int mileage + (String, int) Class #3: Inheritance & Polymorphism Software Design II (CS 220): M. Allen, 25 Jan. 18 + (String, int) + void

More information

Inheritance -- Introduction

Inheritance -- Introduction Inheritance -- Introduction Another fundamental object-oriented technique is called inheritance, which, when used correctly, supports reuse and enhances software designs Chapter 8 focuses on: the concept

More information

CSE 401/M501 Compilers

CSE 401/M501 Compilers CSE 401/M501 Compilers Code Shape II Objects & Classes Hal Perkins Autumn 2018 UW CSE 401/M501 Autumn 2018 L-1 Administrivia Semantics/type check due next Thur. 11/15 How s it going? Reminder: if you want

More information

Classes and Methods עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מבוסס על השקפים של אותו קורס שניתן בשנים הקודמות

Classes and Methods עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מבוסס על השקפים של אותו קורס שניתן בשנים הקודמות Classes and Methods עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מבוסס על השקפים של אותו קורס שניתן בשנים הקודמות 2 Roadmap Lectures 4 and 5 present two sides of OOP: Lecture 4 discusses the static,

More information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++

More information

Implements vs. Extends When Defining a Class

Implements vs. Extends When Defining a Class Implements vs. Extends When Defining a Class implements: Keyword followed by the name of an INTERFACE Interfaces only have method PROTOTYPES You CANNOT create on object of an interface type extends: Keyword

More information

Java Magistère BFA

Java Magistère BFA Java 101 - Magistère BFA Lesson 3: Object Oriented Programming in Java Stéphane Airiau Université Paris-Dauphine Lesson 3: Object Oriented Programming in Java (Stéphane Airiau) Java 1 Goal : Thou Shalt

More information

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

Classes and Methods לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון Classes and Methods לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון 22 Roadmap Lectures 4 and 5 present two sides of OOP: Lecture 4 discusses the static, compile time representation of object-oriented

More information

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are built on top of that. CMSC131 Inheritance Object When we talked about Object, I mentioned that all Java classes are "built" on top of that. This came up when talking about the Java standard equals operator: boolean equals(object

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

An Introduction to Subtyping

An Introduction to Subtyping An Introduction to Subtyping Type systems are to me the most interesting aspect of modern programming languages. Subtyping is an important notion that is helpful for describing and reasoning about type

More information

Compilation of Object Oriented Languages Tik Compilers Seminar

Compilation of Object Oriented Languages Tik Compilers Seminar Compilation of Object Oriented Languages Burlacu Mihai Helsinki University of Technology burlacum@cc.hut.fi Abstract The paper covers briefly the object-oriented concepts, usability and advantages of using

More information

Lecture 36: Cloning. Last time: Today: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting

Lecture 36: Cloning. Last time: Today: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting Lecture 36: Cloning Last time: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting Today: 1. Project #7 assigned 2. equals reconsidered 3. Copying and cloning 4. Composition 11/27/2006

More information

Example: Count of Points

Example: Count of Points Example: Count of Points 1 public class Point { 2... 3 private static int numofpoints = 0; 4 5 public Point() { 6 numofpoints++; 7 } 8 9 public Point(int x, int y) { 10 this(); // calling Line 5 11 this.x

More information

Support for Subtyping and Code Re-use in Timor

Support for Subtyping and Code Re-use in Timor Support for Subtyping and Code Re-use in Timor J. Leslie Keedy, Gisela Menger, Christian Heinlein Department of Computer Structures University of Ulm 89069 Ulm, Germany {keedy,menger,heinlein@informatik.uni-ulm.de

More information

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including:

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including: Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including: Abstraction Encapsulation Inheritance and Polymorphism Object-Oriented

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

Object Model. Object Oriented Programming Spring 2015

Object Model. Object Oriented Programming Spring 2015 Object Model Object Oriented Programming 236703 Spring 2015 Class Representation In Memory A class is an abstract entity, so why should it be represented in the runtime environment? Answer #1: Dynamic

More information

First IS-A Relationship: Inheritance

First IS-A Relationship: Inheritance First IS-A Relationship: Inheritance The relationships among Java classes form class hierarchy. We can define new classes by inheriting commonly used states and behaviors from predefined classes. A class

More information

Java. Classes 3/3/2014. Summary: Chapters 1 to 10. Java (2)

Java. Classes 3/3/2014. Summary: Chapters 1 to 10. Java (2) Summary: Chapters 1 to 10 Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The University of Texas at Arlington, Arlington, TX 76019 Email: sharma@cse.uta.edu

More information

Week 7. Statically-typed OO languages: C++ Closer look at subtyping

Week 7. Statically-typed OO languages: C++ Closer look at subtyping C++ & Subtyping Week 7 Statically-typed OO languages: C++ Closer look at subtyping Why talk about C++? C++ is an OO extension of C Efficiency and flexibility from C OO program organization from Simula

More information

JAVA: A Primer. By: Amrita Rajagopal

JAVA: A Primer. By: Amrita Rajagopal JAVA: A Primer By: Amrita Rajagopal 1 Some facts about JAVA JAVA is an Object Oriented Programming language (OOP) Everything in Java is an object application-- a Java program that executes independently

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages CSE 307: Principles of Programming Languages Classes and Inheritance R. Sekar 1 / 52 Topics 1. OOP Introduction 2. Type & Subtype 3. Inheritance 4. Overloading and Overriding 2 / 52 Section 1 OOP Introduction

More information

Jam: A Smooth Extension With Java Mixins

Jam: A Smooth Extension With Java Mixins Jam: A Smooth Extension With Java Mixins Davide Ancona, Giovanni Lagorio, Ellena Zucca Presentation created by Left-out Jam abstract syntax Formal definitions of Jam static semantics Formal definitions

More information

Technical Report. Computer Science Department. Operating Systems IMMD IV. Friedrich-Alexander-University Erlangen-Nürnberg, Germany

Technical Report. Computer Science Department. Operating Systems IMMD IV. Friedrich-Alexander-University Erlangen-Nürnberg, Germany Towards the Implementation of a Uniform Object Model F. J. Hauck Oktober 1992 TR-I4-5-92 Technical Report Computer Science Department Operating Systems IMMD IV Friedrich-Alexander-University Erlangen-Nürnberg,

More information

Fortgeschrittene objektorientierte Programmierung (Advanced Object-Oriented Programming)

Fortgeschrittene objektorientierte Programmierung (Advanced Object-Oriented Programming) 2014-03-07 Preface Fortgeschrittene objektorientierte Programmierung (Advanced Object-Oriented Programming) Coordinates: Lecturer: Web: Studies: Requirements: No. 185.211, VU, 3 ECTS Franz Puntigam http://www.complang.tuwien.ac.at/franz/foop.html

More information

Lecture 23: Object Lifetime and Garbage Collection

Lecture 23: Object Lifetime and Garbage Collection The University of North Carolina at Chapel Hill Spring 2002 Lecture 23: Object Lifetime and Garbage Collection March 18 1 Fundamental Concepts in OOP Encapsulation Data Abstraction Information hiding The

More information

The Java Type System (continued)

The Java Type System (continued) Object-Oriented Design Lecture 5 CSU 370 Fall 2007 (Pucella) Friday, Sep 21, 2007 The Java Type System (continued) The Object Class All classes subclass the Object class. (By default, this is the superclass

More information

More Relationships Between Classes

More Relationships Between Classes More Relationships Between Classes Inheritance: passing down states and behaviors from the parents to their children Interfaces: grouping the methods, which belongs to some classes, as an interface to

More information