Ceg860 (Prasad)L7Class1 Classes. ceg860 (Prasad)L7Class2 Class :: Instance (Object) Static structure vs Run-time structure (Analogy -- a statue :: Lincoln.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Symbol Table.
Basic -2 Classes and Objects. Classes and Objects A class is a complex data TYPE An object is an instance of a class. Example: Class: Person Objects:
Object-Oriented programming in C++ Classes as units of encapsulation Information Hiding Inheritance polymorphism and dynamic dispatching Storage management.
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
CPS 506 Comparative Programming Languages Abstract Data Type and Encapsulation.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
Lecture 9 Concepts of Programming Languages
Chapter 10 Classes Continued
Abstract Data Types and Encapsulation Concepts
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
OOP Languages: Java vs C++
Ranga Rodrigo. Class is central to object oriented programming.
Language Evaluation Criteria
Comparison of OO Programming Languages © Jason Voegele, 2003.
Appendix A.2: Review of Java and Object-Oriented Programming: Part 2 “For the object-oriented project, remember that the primary unit of decomposition.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Ceg860 (Prasad)L6MR1 Modularity Extendibility Reusability.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
CSC 212 Object-Oriented Programming and Java Part 1.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Computer Science and Engineering College of Engineering The Ohio State University Interfaces The credit for these slides goes to Professor Paul Sivilotti.
Programming Languages and Paradigms Object-Oriented Programming.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Introduction to Object Oriented Programming CMSC 331.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
P Chapter 2 introduces Object Oriented Programming. p OOP is a relatively new approach to programming which supports the creation of new data types and.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Ceg860 (Prasad)LADT1 Specification and Implementation of Abstract Data Types Algebraic Techniques.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Object Oriented Programming
ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
Programming Languages Third Edition Chapter 11 Abstract Data Types and Modules.
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming - Week.
Ceg860(Prasad)L8Obj1 Objects Run-time Structure and Organization.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Ceg860 (Prasad)L17IT1 Inheritance Techniques Subcontracting Anchored Types.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
1 CS Programming Languages Class 22 November 14, 2000.
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
 2005 Pearson Education, Inc. All rights reserved. 1 Classes and Objects: A Deeper Look.
A Survey of Object-Oriented Concept Oscar Nierstrasz.
Prof. I. J. Chung Data Structure #1 Professor I. J. Chung.
Java Primer 1: Types, Classes and Operators
11.1 The Concept of Abstraction
Object Oriented Programming in Java
Lecture 9 Concepts of Programming Languages
Introduction to Data Structure
Lecture 9 Concepts of Programming Languages
Presentation transcript:

ceg860 (Prasad)L7Class1 Classes

ceg860 (Prasad)L7Class2 Class :: Instance (Object) Static structure vs Run-time structure (Analogy -- a statue :: Lincoln Memorial) Class :: Abstract Data Type A class is an ADT equipped with a possibly partial implementation. Class :: Metaclass A metaclass is a class whose instances are classes. (Useful for manipulating class representations at run-time by interpreters, browsers, etc.)

ceg860 (Prasad)L7Class3 Abstraction : Equivalence Relations –Computability Recursive vs Non-recursive –Semantics Behavioral Equivalence –Resource-independent interchangeability »Performance aspect irrelevant for “correctness” –E.g., Groups, Fields, Sorting, UNIX, etc –Complexity (Algorithms) Time and Space requirements –Big-Oh (Worst-case Analysis) –NP-hard vs Polynomial-time

ceg860 (Prasad)L7Class4 Specification of Data Types: Motivation Precise and unambiguous description. Sound and complete description. Avoids over-specification. Spec: Flexible enough to accommodate all possible implementations. Impl.: Constraining enough to exploit representation details for efficiency.

ceg860 (Prasad)L7Class5 Specification of Data Types: Details Type : Values + Operations Specify Syntax Semantics Signature of Ops Meaning of Ops Model-based Axiomatic( Algebraic ) Description in terms of Give axioms satisfied standard “primitive” data types by the operations

ceg860 (Prasad)L7Class6 ADT Table ( symbol table/directory ) empty : Table update : Key x Info x Table  Table lookUp: Key x Table  nfo lookUp(K,empty) = error (Use of variable) (Alternative : Use of Preconditions) lookUp(K,update(Ki, I, T)) = if K = Ki then I else lookUp(K,T) (“last update overrides the others”)

ceg860 (Prasad)L7Class7 Implementations –Array-based –LinearList-based –Tree-based Binary Search Trees, AVL Trees, B-Trees etc –HashTable-based These exhibit a common Table behavior, but differ in performance aspects. Correctness of a client program is assured even when the implementation is changed.

ceg860 (Prasad)L7Class8 To make available certain features to all classes, Java defines a root class ( class Object ) with those features. E.g., Thread support (locks), cloning, equality check, string representation, etc Certain class operations are given special status. E.g., creation and initialization of an object is incorporated via constructors. Meta-programmingMeta-programming is achieved through appropriate libraries supporting Reflection and Introspection. E.g., In Java 1.1, package java.lang.reflect. Java approach to metaclass benefits

ceg860 (Prasad)L7Class9 Class as module and type –Module (unit of software decomposition) Syntactic: Only affects the form of software text, not what the software can do. Separately compilable. –Type (static description of dynamic objects) Semantic: Influences execution of a software system by defining objects manipulated at run-time. The facilities provided by a class, viewed as a module, are precisely the operations on instances of the class.

ceg860 (Prasad)L7Class10 Example : class Point Features/Members –Attributes/Fields ( represented using memory ) –Routines/Methods ( represented using computation ) real x-coord, y-coord; real radius, angle; real distance(Point); void translate(real x,y);

ceg860 (Prasad)L7Class11 Feature Feature Classification by Role Procedure Function Function Attribute (Field) (Field) No resultReturns result ArgumentsNo Arguments ComputationMemory Routine

ceg860 (Prasad)L7Class12 Feature Feature Classification by Implementation ComputationMemory ProcedureFunction No result Result Routine(Method) Attribute (Field) (Field)

ceg860 (Prasad)L7Class13 Uniform Access principle A client should be able to access a property (feature) of an object using a single notation whether the property is implemented by memory or by computation. –Eiffel –Eiffel : 0-ary routine f and attribute f have the same syntax. Attributes cannot be directly assigned. –Java SmallTalkJava Beans, –Java: 0-ary method syntax is f() (not f ). In SmallTalk/Java Beans, a field is accessed via getF() and/or setF( valueType ) methods.

ceg860 (Prasad)L7Class14 Object-Oriented Style of Computation Single Target Principle –Every operation is relative to a certain object. –E.g., pt1.distance(pt2) Current Instance –May be implicit, or referred to explicitly using a keyword such as this (Java/C++), self (Self), Current (Eiffel), etc. Module-Type Identification

ceg860 (Prasad)L7Class15 double distance( Point p ) { if (p =/= this) { return Math.sqrt( (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y) ); } else { return 0; }

ceg860 (Prasad)L7Class16 Composition : Client and Supplier A class C which contains a declaration of the form S x is said to be a client of S. S is said to be a supplier (server) of C. x may be an attribute or a function of C, or a local entity or argument of a routine of C.

ceg860 (Prasad)L7Class17 Feature Calls Qualified calls –x.f or x.f() –x.f(a,b,…) Unqualified calls –f or f() –f(a,b,…) Equivalently, –this.f or this.f() –this.f(a,b,…) Operators infix –associativity prefix –Operator definitions supported in order to be consistent with the standard mathematical notations. – A * B,  5, etc.

ceg860 (Prasad)L7Class18 Selective Export and Information Hiding EiffelEiffel has a general mechanism to export a feature to designated clients and their proper descendants. JavaC++Java and C++ support three levels: –public : all clients. –private : (all instances of) current class. –protected : all subclasses. –Default : package wide visibility.

ceg860 (Prasad)L7Class19 Function In-lining in C++ –Interface file ( “.h ” extension ). Contains prototype declarations, and (short) function definitions that may be in-lined. –Implementation file ( “.c++ ” extension ). Contains function definitions, possibly with inline directive. In-lining enables programmers to have benefits of encapsulation while avoiding some of the run-time costs of function invocation.

ceg860 (Prasad)L7Class20 Genericity Unconstrained ©Type parameterized classes  Generic type : List[G]  Instantiations: List[int], List[String], List[Window], etc Constrained ©Types with operations  Constrained Genericity: Ordered, Group, etc  Java interface types.

ceg860 (Prasad)L7Class21 type INTMAT is array ( POSITIVE range <>, POSITIVE range <>) of integer; function int_sum_all( M : INTMAT ) return integer is sum : integer := 0; begin for I in M'range(1) loop for J in M'range(2) loop sum := sum + M(I,J); end loop; return (sum); end;

ceg860 (Prasad)L7Class22 generic type ET is private; type INDEX is (<>); ID : ET;type AR is array ( INDEX range <>, INDEX range <>) of ET; with function "+" ( X,Y : ET ) return ET is <>; function sum_all( M : AR ) return ET; function sum_all( M : AR ) return ET is sum : ET := ID; begin for I in M'range(1) loop for J in M'range(2) loop sum := sum + M(I,J); end loop; return (sum); end;