1 Object Oriented Programming Daniel Albu Based on a lecture by John Mitchell Reading: Chapter 10.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Type Systems and Object- Oriented Programming (III) John C. Mitchell Stanford University.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
1 OBJECT-ORIENTED CONCEPTS. 2 What is an object?  An object is a software entity that mirrors the real world in some way.  A software object in OOP.
Modularity and Object-Oriented Programming John Mitchell CS 242 Reading: Chapter 10 and parts of Chapter 9.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
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.
1 CMSC 132: Object-Oriented Programming II Software Development IV Department of Computer Science University of Maryland, College Park.
Object-oriented Programming Concepts
Object Oriented Databases - Overview
Abstract Data Types and Encapsulation Concepts
Concepts in Object-Oriented Programming Languages Slides Today Taken From John Mitchell.
C++ fundamentals.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
Slide 1 Vitaly Shmatikov CS 345 Modularity and Object-Oriented Programming.
 Computer Science 1MD3 Introduction to Programming Michael Liut Ming Quan Fu Brandon.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Introduction to Object-oriented programming and software development Lecture 1.
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
An Object-Oriented Approach to Programming Logic and Design
Sadegh Aliakbary Sharif University of Technology Fall 2011.
CONCEPTS OF OBJECT ORIENTED PROGRAMMING. Topics To Be Discussed………………………. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
School of Computer Science & Information Technology G6DICP - Lecture 22 The Theory of Object Oriented Programming.
Design Patterns in Java Chapter 1 Introduction Summary prepared by Kirk Scott 1.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
ProgrammingLanguages Programming Languages Object-oriented Programming Languages This lecture discusses the concept of object- oriented programming.
Computer Science II 810:062 Section 01. How is CS I different from CS II? When you teach Java there are a series of decisions that have to be made…
Guided Notes Ch. 9 ADT and Modules Ch. 10 Object-Oriented Programming PHP support for OOP and Assignment 4 Term project proposal C++ and Java Designer.
OOP Class Lawrence D’Antonio Lecture 3 An Overview of C++
SNPL1 Woochang Lim What (Variable) + How (Function) = Object Objects are the physical and conceptual things we find in the universe around us. Object-Oriented.
OBJECT-ORIENTED PROGRAMMING (OOP) WITH C++ Instructor: Dr. Hany H. Ammar Dept. of Electrical and Computer Engineering, WVU.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Kal Bugrara, Ph.DSoftware Engineering Northeastern University Fundamentals Of Software Engineering Lecture V.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
1 Programming for Engineers in Python Autumn Lecture 6: More Object Oriented Programming.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Basic Concepts of Object Orientation Object-Oriented Analysis CIM2566 Bavy LI.
Salman Marvasti Sharif University of Technology Winter 2015.
Modularity and Object-Oriented Programming John Mitchell CS 242 Reading: Chapter 10 and parts of Chapter 9.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
Design Reuse Earlier we have covered the re-usable Architectural Styles as design patterns for High-Level Design. At mid-level and low-level, design patterns.
S.Ducasse Stéphane Ducasse 1 Essential OO Concepts Stéphane Ducasse.
OOP (Object Oriented Programming) Lecture 1. Why a new paradigm is needed? Complexity Five attributes of complex systems –Frequently, complexity takes.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
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.
Classes, Interfaces and Packages
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Lecture 2 Object-oriented programming. Definitions of OOP OOP is a programming paradigm, which utilizes encapsulation, inheritance and polymorphism. (From.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
Object-Oriented Programming “The Rest of the Story”, CS 4450 – Chapter 16.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
ISBN Chapter 12 Support for Object-Oriented Programming.
1 Case Study: Meta Classes  Class representation in memory  Class variables and class methods  Meta Classes  3 Level System  4 Level System  5 Level.
Object-Oriented Analysis and Design
MPCS – Advanced java Programming
Multi-Methods in Cecil
The Object-Oriented Thought Process Chapter 1
OOP What is problem? Solution? OOP
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Advanced Programming Behnam Hatami Fall 2017.
Introduction to Data Structure
Languages and Compilers (SProg og Oversættere)
Presentation transcript:

1 Object Oriented Programming Daniel Albu Based on a lecture by John Mitchell Reading: Chapter 10

Object-oriented programming 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

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 If we need a certain operation to be able to perform various commands according to its input, we need to use, for example, the switch-case structure.

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

"Abstraction and encapsulation are complementary concepts: abstraction focuses on the observable behavior of an object... encapsulation focuses upon the implementation that gives rise to this behavior... encapsulation is most often achieved through information hiding, which is the process of hiding all of the secrets of object that do not contribute to its essential characteristics." -Grady Booch in Object Oriented Analysis and Design (one of the developers of UML)

Encapsulation uBuilder of a concept has detailed view uUser of a concept has “abstract” view uEncapsulation separates these two views Implementation code: operate on representation Client code: operate by applying fixed set of operations provided by implementer of abstraction message Object

Language concepts u“Dynamic lookup” different code for different object integer “+” different from real “+” uEncapsulation Implementer of a concept has detailed view User has “abstract” view Encapsulation separates these two views 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 uDue to inheritance, if we update / fix / change the original object, the changes are also rolled to objects inheriting from it.

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 reusing point implementation Technique used by implementer 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 Things like size and circumference are calculated in a different way in these 2 shapes and thus need to be implemented separately and cannot be inherited.

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 e.g. we want to reduce the size of all the shapes currently on screen

Example use: Processing Loop Remove shape from work queue Perform action Control loop does not know the type of each shape e.g. we want to reduce the size of all the shapes currently on screen resize(0.5)

Example use: Processing Loop Remove shape from work queue Perform action Control loop does not know the type of each shape e.g. we want to reduce the size of all the shapes currently on screen resize(0.5)

Example use: Processing Loop Remove shape from work queue Perform action Control loop does not know the type of each shape e.g. we want to reduce the size of all the shapes currently on screen resize(0.5)

Example use: Processing Loop Remove shape from work queue Perform action Control loop does not know the type of each shape e.g. we want to reduce the size of all the shapes currently on screen resize(0.5)

Example use: Processing Loop Remove shape from work queue Perform action Control loop does not know the type of each shape e.g. we want to reduce the size of all the shapes currently on screen resize(0.5)

Just make sure that every object you run the resize function on, has it implemented in it

Subtyping - refers to compatibility of interfaces. A type B is a subtype of A if every function that can be invoked on an object of type A can also be invoked on an object of type B. Inheritance - refers to reuse of implementations. A type B inherits from another type A if some functions for B are written in terms of functions of A. So what’s the difference?

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

Example Design Patterns uSingleton pattern There should only be one object of the given class package { public class Singleton { private static var _instance:Singleton; public function Singleton(lock:SingletonLock) { } public static function getInstance():Singleton { if (_instance == null) _instance = new Singleton(new SingletonLock()); return _instance; } class SingletonLock { }

Example Design Patterns uVisitor design pattern Apply an operation to all parts of structure Generalization of maplist, related functions Standard programming solution: –Each element classes has accept method that takes a visitor object as an argument –Visitor is interface with visit() method for each element class –The accept() method of an element class calls the visit() method for its class

Taken from:

Façade Design Pattern uis a structural object pattern, which means it is a pattern related to composing objects into larger structures containing man objects. uImplementation: relatively little actual code uExample: A compiler

Closures as objects? public function Main() { init(); } public function init():void { //create a counter var counter1:Function = newCounter(); trace( counter1() );//1 trace( counter1() );//2 trace( counter1() );//3 var counter2:Function = newCounter(); trace( counter2() );//1 trace( counter2() );//2 trace( counter1() );//4 --> scope of i is still with counter1 } public function newCounter():Function { var i:int = 0; //variable i gets bound into returned anonymous function return function():int { //i is available to the scope of the anonymous function i=i+1; return i; }

History of class-based languages 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 uActionScript ’s Adapted Java ideas into Flash

Varieties of OO languages uclass-based languages (C++, Java, …) behavior of object determined by its class uobject-based (Self, JavaScript) objects defined directly umulti-methods (CLOS) operation depends on all operands (Common Lisp Object System)

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?

This presentation can be downloaded from: