Concepts in Object-Oriented Programming Languages Slides Today Taken From John Mitchell.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Type Systems and Object- Oriented Programming (III) John C. Mitchell Stanford University.
CMSC 202 Fall 2010, Advanced Section Designing with Objects.
1 CIS601: Object-Oriented Programming in C++ Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised.
Modularity and Object-Oriented Programming John Mitchell CS 242 Reading: Chapter 10 and parts of Chapter 9.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
1 SWE Introduction to Software Engineering Lecture 23 – Architectural Design (Chapter 13)
Object Oriented System Development with VB .NET
1 Object Oriented Programming Daniel Albu Based on a lecture by John Mitchell Reading: Chapter 10.
Stéphane Ducasse6.1 Essential Concepts Why OO? What is OO? What are the benefits? What are the KEY concepts? Basis for all the lectures.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Chapter 10 Classes Continued
Object Oriented Databases - Overview
Abstract Data Types and Encapsulation Concepts
C++ fundamentals.
CS 171: Introduction to Computer Science II Stacks Ymir Vigfusson.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Slide 1 Vitaly Shmatikov CS 345 Modularity and Object-Oriented Programming.
Chapter 9 High-Level Programming Languages: C++. Chapter Goals Describe the expectations of high level languages Distinguish between functional design.
Introduction To System Analysis and design
Copyright © 2002, Systems and Computer Engineering, Carleton University Intro.ppt * Object-Oriented Software Development Unit 1 Course.
Introduction to Object-oriented programming and software development Lecture 1.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Ceg860 (Prasad)L6MR1 Modularity Extendibility Reusability.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Object Oriented Programming Principles Lecturer: Kalamullah Ramli Electrical Engineering Dept. University of Indonesia Session-3.
OOP Class Lawrence D’Antonio Lecture 3 An Overview of C++
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
SNPL1 Woochang Lim What (Variable) + How (Function) = Object Objects are the physical and conceptual things we find in the universe around us. Object-Oriented.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
OBJECT-ORIENTED PROGRAMMING (OOP) WITH C++ Instructor: Dr. Hany H. Ammar Dept. of Electrical and Computer Engineering, WVU.
Object-Oriented Paradigm and UML1 Introduction to the Object- Oriented Paradigm.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Data Abstaraction Chapter 10.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Abstraction ADTs, Information Hiding and Encapsulation.
1 Programming for Engineers in Python Autumn Lecture 6: More Object Oriented Programming.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Salman Marvasti Sharif University of Technology Winter 2015.
1 Languages and Compilers (SProg og Oversættere) Abstract Data Types and Object Oriented Features Bent Thomsen Department of Computer Science Aalborg University.
Modularity and Object-Oriented Programming John Mitchell CS 242 Reading: Chapter 10 and parts of Chapter 9.
1 Languages and Compilers (SProg og Oversættere) Abstract Data Types and Object Oriented Features Bent Thomsen Department of Computer Science Aalborg University.
Object Oriented Programming
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
1 Software Design Lecture What’s Design It’s a representation of something that is to be built. i.e. design  implementation.
S.Ducasse Stéphane Ducasse 1 Essential OO Concepts Stéphane Ducasse.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
1 CS Programming Languages Class 22 November 14, 2000.
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Chapter 2 Principles of Programming and Software Engineering.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Abstract Data Types and Encapsulation Concepts
OOP What is problem? Solution? OOP
11.1 The Concept of Abstraction
Abstract Data Types and Encapsulation Concepts
Introduction to Data Structure
Languages and Compilers (SProg og Oversættere)
Presentation transcript:

Concepts in Object-Oriented Programming Languages Slides Today Taken From John Mitchell

Outline of lecture uObject-oriented design uPrimary object-oriented language concepts dynamic lookup encapsulation inheritance subtyping uProgram organization Work queue, geometry program, design patterns uComparison Objects as closures?

Objects uAn object consists of hidden data instance variables, also called member data hidden functions also possible public operations methods or member functions can also have public variables in some languages uObject-oriented program: Send messages to objects hidden data method 1 msg 1... method n msg n

What’s interesting about this? uUniversal encapsulation construct Data structure File system Database Window Integer uMetaphor usefully ambiguous sequential or concurrent computation distributed, sync. or async. communication

Object-oriented programming uProgramming methodology organize concepts into objects and classes build extensible systems uLanguage concepts encapsulate data and functions into objects subtyping allows extensions of data types inheritance allows reuse of implementation

Object-oriented Method [Booch] uFour steps Identify the objects at a given level of abstraction Identify the semantics (intended behavior) of objects Identify the relationships among the objects Implement these objects uIterative process Implement objects by repeating these steps uNot necessarily top-down “Level of abstraction” could start anywhere

This Method uBased on associating objects with components or concepts in a system uWhy iterative? An object is typically implemented using a number of constituent objects Apply same methodology to subsystems, underlying concepts

uCar object: Contains list of main parts (each an object) –chassis, body, engine, drive train, wheel assemblies Method to compute weight –sum the weights to compute total uPart objects: Each may have list of main sub-parts Each must have method to compute weight Example: Compute Weight of Car

Comparison to top-down design u Similarity: A task is typically accomplished by completing a number of finer-grained sub-tasks uDifferences: Focus of top-down design is on program structure OO methods are based on modeling ideas Combining functions and data into objects makes data refinement more natural (I think)

Object-Orientation uProgramming methodology organize concepts into objects and classes build extensible systems uLanguage concepts dynamic lookup encapsulation subtyping allows extensions of concepts inheritance allows reuse of implementation

Dynamic Lookup u In object-oriented programming, object  message (arguments) code depends on object and message uIn conventional programming, operation (operands) meaning of operation is always the same Fundamental difference between abstract data types and objects

Example uAdd two numbers x  add (y) different add if x is integer, complex uConventional programming add (x, y) function add has fixed meaning Very important distinction: Overloading is resolved at compile time, Dynamic lookup at run time

Language concepts u“dynamic lookup” different code for different object integer “+” different from real “+” uencapsulation usubtyping uinheritance

Encapsulation uBuilder of a concept has detailed view uUser of a concept has “abstract” view uEncapsulation is the mechanism for separating these two views message Object

Comparison uTraditional approach to encapsulation is through abstract data types uAdvantage Separate interface from implementation uDisadvantage Not extensible in the way that OOP is We will look at ADT’s example to see what problem is

Abstract data types abstype q with mk_Queue : unit -> q is_empty : q -> bool insert : q * elem -> q remove : q -> elem is … in program end

Priority Q, similar to Queue abstype pq with mk_Queue : unit -> pq is_empty : pq -> bool insert : pq * elem -> pq remove : pq -> elem is … in program end But cannot intermix pq’s and q’s

Abstract Data Types uGuarantee invariants of data structure only functions of the data type have access to the internal representation of data uLimited “reuse” Cannot apply queue code to pqueue, except by explicit parameterization, even though signatures identical Cannot form list of points, colored points uData abstraction is important part of OOP, innovation is that it occurs in an extensible form

Language concepts u“dynamic lookup” different code for different object integer “+” different from real “+” uencapsulation usubtyping uinheritance

Subtyping and Inheritance uInterface The external view of an object uSubtyping Relation between interfaces uImplementation The internal representation of an object uInheritance Relation between implementations

Object Interfaces uInterface The messages understood by an object uExample: point x-coord : returns x-coordinate of a point y-coord : returns y-coordinate of a point move : method for changing location uThe interface of an object is its type.

Subtyping uIf interface A contains all of interface B, then A objects can also be used B objects. uColored_point interface contains Point Colored_point is a subtype of Point Point x-coord y-coord move Colored_point x-coord y-coord color move change_color

Inheritance uImplementation mechanism uNew objects may be defined by reusing implementations of other objects

Example class Point private float x, y public point move (float dx, float dy); class Colored_point private float x, y; color c public point move(float dx, float dy); point change_color(color newc); uSubtyping Colored points can be used in place of points Property used by client program uInheritance Colored points can be implemented by resuing point implementation Propetry used by implementor of classes

OO Program Structure uGroup data and functions uClass Defines behavior of all objects that are instances of the class uSubtyping Place similar data in related classes uInheritance Avoid reimplementing functions that are already defined

Example: Geometry Library uDefine general concept shape uImplement two shapes: circle, rectangle uFunctions on implemented shapes center, move, rotate, print uAnticipate additions to library

Shapes uInterface of every shape must include center, move, rotate, print uDifferent kinds of shapes are implemented differently Square: four points, representing corners Circle: center point and radius

Subtype hierarchy Shape CircleRectangle uGeneral interface defined in the shape class uImplementations defined in circle, rectangle uExtend hierarchy with additional shapes

Code placed in classes uDynamic lookup circle  move(x,y) calls function c_move uConventional organization Place c_move, r_move in move function centermoverotateprint Circlec_centerc_movec_rotatec_print Rectangler_centerr_mover_rotater_print

Example use: Processing Loop Remove shape from work queue Perform action Control loop does not know the type of each shape

Subtyping differs from inheritance Collection Set Sorted Set Indexed Array Dictionary String Subtyping Inheritance

Design Patterns uClasses and objects are useful organizing concepts uCulture of design patterns has developed around object-oriented programming Shows value of OOP for program organization and problem solving

What is a design pattern? uGeneral solution that has developed from repeatedly addressing similar problems. uExample: singleton Restrict programs so that only one instance of a class can be created Singleton design pattern provides standard solution uNot a class template Using most patterns will require some thought Pattern is meant to capture experience in useful form Standard reference: Gamma, Helm, Johnson, Vlissides

OOP in Conventional Language uRecords provide “dynamic lookup” uScoping provides another form of encapsulation Try object-oriented programming in ML. Will it work? Let’s see what’s fundamental to OOP

Dynamic Lookup (again) receiver  operation (arguments) code depends on receiver and operation This is may be achieved in conventional languages using record with function components

Stacks as closures fun create_stack(x) = let val store = ref [x] in {push = fn (y) => store := y::(!store), pop = fn () => case !store of nil => raise Empty | y::m => (store := m; y) } end; val stk = create_stack(1); stk = {pop=fn,push=fn} : {pop:unit -> int, push:int -> unit}

Does this work ??? uDepends on what you mean by “work” uProvides encapsulation of private data dynamic lookup uBut cannot substitute extended stacks for stacks only weak form of inheritance –can add new operations to stack –not mutually recursive with old operations

Varieties of OO languages uclass-based languages behavior of object determined by its class uobject-based objects defined directly umulti-methods operation depends on all operands This course: class-based languages

History uSimula 1960’s Object concept used in simulation uSmalltalk 1970’s Object-oriented design, systems uC ’s Adapted Simula ideas to C uJava 1990’s Distributed programming, internet

Summary uObject-oriented design uPrimary object-oriented language concepts dynamic lookup encapsulation inheritance subtyping uProgram organization Work queue, geometry program, design patterns uComparison Objects as closures?

Example: Container Classes uDifferent ways of organizing objects Set: unordered collection of objects Array: sequence, indexed by integers Dictionary: set of pairs, (word, definition) String: sequence of letters uDeveloped as part of Smalltalk system

Next lectures uSimula and Smalltalk uC++ uJava