Ceg860(Prasad)L8Obj1 Objects Run-time Structure and Organization.

Slides:



Advertisements
Similar presentations
ACM/JETT Workshop - August 4-5, Classes, Objects, Equality and Cloning.
Advertisements

Pointers Prasun Dewan Comp 114.
Programming Languages and Paradigms
Names and Bindings.
Chapter 7:: Data Types Programming Language Pragmatics
1 Class Design CS 3331 Fall Outline  Organizing classes  Design guidelines  Canonical forms of classes equals method hashCode method.
Compiler Construction
6/10/2015C++ for Java Programmers1 Pointers and References Timothy Budd.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Reference Types. 2 Objectives Introduce reference types –class –array Discuss details of use –declaration –allocation –assignment –null –parameter –aggregation.
Miscellaneous OOP topics Java review continued. Simple data types & wrapper classes Simple data types are the built-in types provided as part of the Java.
Lecture 9 Concepts of Programming Languages
Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.
OOP Languages: Java vs C++
Types(2). 2 Recursive Problems  One or more simple cases of the problem have a straightforward, nonrecusive solution  The other cases can be redefined.
Programming Languages and Paradigms Object-Oriented Programming.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
Data Structures Using C++ 2E Chapter 3 Pointers and Array-Based Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Imperative Programming Part One. 2 Overview Outline the characteristics of imperative languages Discuss other features of imperative languages that are.
Names Variables Type Checking Strong Typing Type Compatibility 1.
5-1 Chapter 5: Names, Bindings, Type Checking, and Scopes Variables The Concept of Binding Type Checking Strong Typing Type Compatibility Scope and Lifetime.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
CSC Programming I Lecture 8 September 9, 2002.
Java Classes Appendix C © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.
Programming Languages and Paradigms Object-Oriented Programming.
Slide: 1 Copyright © AdaCore Subprograms Presented by Quentin Ochem university.adacore.com.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
Constructors CMSC 202. Object Creation Objects are created by using the operator new in statements such as… The following expression invokes a special.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 4 – August 30, 2001.
1 Records Record aggregate of data elements –Possibly heterogeneous –Elements/slots are identified by names –Elements in same fixed order in all records.
Data Structures Using C++ 2E Chapter 3 Pointers. Data Structures Using C++ 2E2 Objectives Learn about the pointer data type and pointer variables Explore.
Chapter 8 Objects and Classes Object Oriented programming Instructor: Dr. Essam H. Houssein.
More C++ Features True object initialisation
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Objects and Classes Mostafa Abdallah
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
Object Management. Constructors –Compiler-generated –The Initializer List –Copy Constructors –Single-arg (conversion ctors) The Assignment Operator.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
OOP in C++ CS 124. Program Structure C++ Program: collection of files Source (.cpp) files be compiled separately to be linked into an executable Files.
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming - Week.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
By Mr. Muhammad Pervez Akhtar
The Prototype Pattern (Creational) ©SoftMoore ConsultingSlide 1.
COM S 228 Introduction to Data Structures Instructor: Ying Cai Department of Computer Science Iowa State University Office: Atanasoff.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Chapter 1 C++ Basics Review (Section 1.4). Classes Defines the organization of a data user-defined type. Members can be  Data  Functions/Methods Information.
Sections Basic Data Structures. 1.5 Data Structures The way you view and structure the data that your programs manipulate greatly influences your.
Value Types. 2 Objectives Discuss concept of value types –efficiency –memory management –value semantics –boxing –unboxing –simple types Introduce struct.
Records type city is record -- Ada Name: String (1..10); Country : String (1..20); Population: integer; Capital : Boolean; end record; struct city { --
Type Checking and Type Inference
Java Primer 1: Types, Classes and Operators
Records Design Issues: 1. What is the form of references?
Object Oriented Programming in Java
Java Review: Reference Types
Java Programming Language
Review for Midterm 3.
Classes and Objects Object Creation
Lecture 7: Types (Revised based on the Tucker’s slides) 10/4/2019
SPL – PS3 C++ Classes.
CMSC 202 Constructors Version 9/10.
Presentation transcript:

ceg860(Prasad)L8Obj1 Objects Run-time Structure and Organization

ceg860(Prasad)L8Obj2 Fields Fields : Structural Aspect Basic Types ( int, real, bool, char, etc.) –E.g., class Point { real x, y; } Sub-objects –E.g, class Person { String name; …} class Car { Person owner; …} Wastes memory space. Fails to express sharing of objects : Update consistency problem.

ceg860(Prasad)L8Obj3 References reference attachedA reference is a run-time value which is either null or attached. attachedIf attached, it identifies a single object. –The concrete representation of a reference may include an address (pointer), type info, etc. unique identityEvery object has a unique identity, independent of its value as defined by its fields. –Object reference can serve as object identity.

ceg860(Prasad)L8Obj4 Object Identity Two objects with different identities may have identical fields. (Cf. Java == vs equal ) (Cf. Scheme’s eq vs equal ) (Cf. Ada’s limited private type ) (Cf. Eiffel’s = vs equal vs deep_equal ) Conversely, the fields of a certain object may change during the execution; but this does not affect the object’s identity. –Objects with state

ceg860(Prasad)L8Obj5 Effect of Basic constructor Cl var; Cl var = new Cl(); Create a new instance of Cl called nCl. Initialize each field of nCl using standard default values. Int : 0, Class : null, bool : false, etc Attach ncl to var (a reference).

ceg860(Prasad)L8Obj6 Why create objects explicitly? Implicit creation highly inefficient (impossible for recursive structures). –Self-reference implies non-termination. Realistic modeling can require null reference or values of two fields to be attached to the same object (sharing). –Representing Relations and Functions.

ceg860(Prasad)L8Obj7 Overloading Constructors To override language-defined defaults. Java/C++Java/C++ : Signature-based resolution. EiffelEiffel: Named constructors. Ensure object satisfies consistency constraints imposed by ADT spec. E.g., Age = Year of Birth  Current Year Support for programmer defined initializations. E.g., Label, Color, Location, etc of a Button.

ceg860(Prasad)L8Obj8 C++ Example class Complex { public: Complex(double); Complex(); private: double re, im; } Complex pi = 3.14; Complex e (2.71); Complex:: Complex ( double r){ re = r; im = 0; } Complex:: Complex( double r): re(r), im(0) {}

ceg860(Prasad)L8Obj9 Entity Reference Object target.feature(args) exception –If target = null, then an exception will be triggered at run-time. Entity, Reference, Object

ceg860(Prasad)L8Obj10 Operations on References Reference Assignment ( Cl x = y; ) –Sharing of objects (Reattachment) : Entities x and y now refer to the same object. Dynamic aliasing. –Garbage Collection (Recycling) : If the object, referred to by x initially, becomes unattached (“unreachable”) now, it may be recycled. Reference Comparison –Equal (==) and Not Equal (=/=)

ceg860(Prasad)L8Obj11 Cloning and Copying x.clone(y) x is attached to an object (say, OX) that is a duplicate of the object attached to y (say, OY). The corresponding fields of OX and OY have identical values. Shallow copy : clone is not recursive. –Deep cloning duplicates a structure recursively without introducing any sharing of references. x.copy(y) Both x and y must be non-null.

ceg860(Prasad)L8Obj12 Persistence Motivation: Communication with other systems –Read/Write objects from/to files, databases, and other devices. In practice: –Require a mechanism to store and retrieve objects containing references. Java 1.1 Serialization and ObjectStreams Eiffel: class Storable –Require context to determine the type of the retrieved object.

ceg860(Prasad)L8Obj13 Composite Objects : Expanded Types Eiffel: expanded Cl x; vs Cl y; C++: Cl x; vs Cl* y; The value of entity x is an instance of Cl. Available in C++ and Ada-95. Not available in Java. The value of entity y is a reference to an instance of Cl. Available in Java, C++, and Ada-95.

ceg860(Prasad)L8Obj14 Motivation for expanded types Enhanced modeling power. Class WorkStation { k: expanded KeyBoard; c: expanded CPU; m: expanded Monitor; n: Network; } –Every instance of Workstation has (contains) an instance of CPU. (Not shared.) Can improve (space and time) efficiency. –Cyclic dependency prohibited.