Lecture 10: Part 1: OO Issues CS 540 George Mason University.

Slides:



Advertisements
Similar presentations
Object-Oriented Programming Session 9 Course : T Programming Language Concept Year : February 2011.
Advertisements

Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Type Systems and Object- Oriented Programming (III) John C. Mitchell Stanford University.
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University.
Chapter 1 OO using C++. Abstract Data Types Before we begin we should know how to accomplish the goal of the program We should know all the input and.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
The Procedure Abstraction Part IV: Run-time Structures for OOLs Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students.
Introduction to Data Structures, Spring 2007 Slide- 1 California State University, Fresno Introduction to Data Structure Object Oriented Programming Concepts.
CS 536 Spring Code Generation II Lecture 21.
Static and Dynamic Behavior Fall 2005 OOPD John Anthony.
Chapter 7: Inheritance Abstract Data Types Object Hierarchy Inheritance of Methods Inheritance: implicit passing of information between program components.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
CS 355 – PROGRAMMING LANGUAGES Dr. X. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 12 Topics Introduction Object-Oriented Programming.
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
Chapter 8 :: Subroutines and Control Abstraction
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Adapted from Prof. Necula UCB CS 1641 Overview of COOL ICOM 4029 Lecture 2 ICOM 4029 Fall 2008.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
Runtime Environments Compiler Construction Chapter 7.
The Procedure Abstraction, Part VI: Inheritance in OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
CSSE501 Object-Oriented Development. Chapter 12: Implications of Substitution  In this chapter we will investigate some of the implications of the principle.
Procedure Abstraction VI Run-time structures for OOLs ( II ) and Wrap-up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
The Procedure Abstraction, Part V: Support for OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
OOP and Dynamic Method Binding Chapter 9. Object Oriented Programming Skipping most of this chapter Focus on 9.4, Dynamic method binding – Polymorphism.
Introduction to Object Oriented Programming CMSC 331.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
CS 2130 Lecture 5 Storage Classes Scope. C Programming C is not just another programming language C was designed for systems programming like writing.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
COMP3190: Principle of Programming Languages
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
Compiling Objects in Class-Based Languages CS 153: Compilers.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Chapter 12 Support for Object-Oriented Programming.
Object-Oriented Programming Chapter Chapter
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
ISBN Object-Oriented Programming Chapter Chapter
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
Lecture 12 Implementation Issues with Polymorphism.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
CSCI-383 Object-Oriented Programming & Design Lecture 17.
ISBN Chapter 12 Support for Object-Oriented Programming.
©2004 Joel Jones 1 CS 403: Programming Languages Lecture 3 Fall 2004 Department of Computer Science University of Alabama Joel Jones.
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
Modern Programming Tools And Techniques-I
Object-Oriented Design
Name Spaces: ALL versus OOL
Names and Attributes Names are a key programming language feature
Support for Object-Oriented Programming
Support for Object-Oriented Programming
Types of Programming Languages
Object Oriented Analysis and Design
Names, Binding, and Scope
Code Shape II – Objects & Classes Hal Perkins Autumn 2011
The Procedure Abstraction Part V: Run-time Structures for OOLs
Support for Object-Oriented Programming
Binding Times Binding is an association between two things Examples:
Support for Object-Oriented Programming
Lecture 10 Concepts of Programming Languages
ICOM 4029 Fall 2003 Lecture 2 (Adapted from Prof. Necula UCB CS 164)
Run-time environments
Presentation transcript:

Lecture 10: Part 1: OO Issues CS 540 George Mason University

CS 540 Spring 2004 GMU Object-Oriented Languages? What is an OOL? A language that supports “object-oriented programming” Term is almost meaningless today — Smalltalk to C++ to Java How does an OOL differ from an imperative language? Complex type system including inheritance and polymorphism. Object representation issues Resolution of names to their implementations

CS 540 Spring 2004 GMU An object is an abstract data type that encapsulates data, operations and internal state behind a simple, consistent interface. Elaborating the concepts: Each object needs local storage for its attributes –Attributes are static (lifetime of object ) –Access is through methods Some methods are public, others are private Object’s internal state leads to complex behavior Data Code x Data Code y Data Code z The Concept:

CS 540 Spring 2004 GMU Implementing Object-Oriented Languages Two critical issues in OOL implementation: Object representation Mapping a method invocation name to a method implementation These both are intimately related to the OOL’s name space Object Representation Static, private storage for attributes & instance variables –Heap allocate object records or “instances” Need consistent, fast access –Known, constant offsets Provision for initialization in NEW

CS 540 Spring 2004 GMU Simplistic method: Object Representation f1 code f2 code b: c: z f1 f2 f1 code f2 code b: c: z f1 f2 Each object gets copies of all attributes and methods Class A { int b,c; A z; f1() f2() } For object x of type A:

CS 540 Spring 2004 GMU Better method b: c: z f1 f2 b: c: z f1 f2 Objects share methods (and static attributes) Class A { int b,c; A z; f1() f2() } For object x of type A: f1 code f2 code

CS 540 Spring 2004 GMU More typically: b: c: z Objects share methods (and static attributes) via shared class object (can keep counter of objects N) b: c: z N: 2 d: f1 f2 parent class Class A { int b,c; static int d A z; f1() f2() } For object x of type A: f1 code f2 code Class A

CS 540 Spring 2004 GMU OOL Storage Layout Class variables Static class storage accessible by global name (class C) –Method code put at fixed offset from start of class area –Static variables and class related bookkeeping Object Variables Object storage is heap allocated at object creation –Fields at fixed offsets from start of object storage Methods –Code for methods is stored with the class –Methods accessed by offsets from code vector Allows method references inline –Method local storage in object (no calls) or on stack

CS 540 Spring 2004 GMU Dealing with Single Inheritance Use prefixing of storage for objects Class Point { int x, y; } Class ColorPoint extends Point { Color c; } x y x y c self

CS 540 Spring 2004 GMU Object-Oriented Languages - Dispatching Mapping message names to methods Static mapping, known at compile-time (Java, C++) –Fixed offsets & indirect calls Dynamic mapping, unknown until run-time (Smalltalk, C++ with pointers) –Look up name in class’ table of methods This is really a data-structures problem Build a table of function pointers Use a standard invocation sequence

CS 540 Spring 2004 GMU Single Inheritance and Dynamic Dispatch Class Point { int x, y; public void draw(); public void d2o(); } Class ColorPoint extends Point { Color c; public void draw(); public void rev(); } x y table draw d2o draw d2o table rev Point: draw ColorPoint:draw ColorPoint: rev Point: d20 self x y c

CS 540 Spring 2004 GMU Multiple Inheritance The idea Allow more flexible sharing of methods & attributes Relax the inclusion requirement If B is a subclass of A, it need not implement all of A’s methods Need a linguistic mechanism for specifying partial inheritance Problems when C inherits from both A & B C’s method table can extend A or B, but not both –Layout of an object record for C becomes tricky Other classes, say D, can inherit from C & B –Adjustments to offsets become complex Both A & B might provide fum() — which is seen in C ? –C++ produces a “syntax error” when fum() is used