School of Computer Science & Information Technology G6DICP - Lecture 22 The Theory of Object Oriented Programming.

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Advertisements

Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
4. Object-Oriented Programming Procedural programming Structs and objects Object-oriented programming Concepts and terminology Related keywords.
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
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.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
1 G54PRG Programming Lecture 1 Amadeo Ascó Adam Moore 20 Object Oriented Theory II.
C++ Inheritance Gordon College CPS212. Basics OO-programming can be defined as a combination of Abstract Data Types (ADTs) with Inheritance and Dynamic.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
CS-2135 Object Oriented Programming
Object-Oriented PHP (1)
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Chapter 7 l Inheritance Basics l Programming with Inheritance l Dynamic Binding and Polymorphism Inheritance.
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.
16/22/2015 2:54 PM6/22/2015 2:54 PM6/22/2015 2:54 PMObject-Oriented Development Concept originated with simulating objects and their interactions. Adapted.
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Inheritance and Polymorphism CS351 – Programming Paradigms.
Distribution of Marks Internal Sessional Evaluation Assignments – 10 Quizzes – 10 Class Participation Attendence – 5 Mid – Term Test – 25 External Evaluation.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
BACS 287 Basics of Object-Oriented Programming 1.
1 INTRODUCTION TO OOP Objective: Know the difference between functional programming and OOP Know basic terminology in OOP Know the importance of OOP Know.
Object Oriented Software Development
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
An Object-Oriented Approach to Programming Logic and Design
CONCEPTS OF OBJECT ORIENTED PROGRAMMING. Topics To Be Discussed………………………. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
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.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
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.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Learners Support Publications Object Oriented Programming.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Review Class Inheritance, Abstract, Interfaces, Polymorphism, GUI (MVC)
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
1 OOP - An Introduction ISQS 6337 John R. Durrett.
Object Oriented Programming
ISBN Object-Oriented Programming Chapter Chapter
Introduction to OOP CPS235: Introduction.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Classes, Interfaces and Packages
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
OBJECT ORIENTED PROGRAMMING. Design principles for organizing code into user-defined types Principles include: Encapsulation Inheritance Polymorphism.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Testing in OO Environment The reasons for testing is not any different for any of the design and implementation methodologies, including OO methodology.
CSCI-383 Object-Oriented Programming & Design Lecture 17.
Visit for more Learning Resources
Object Oriented Programming
Sachin Malhotra Saurabh Choudhary
Programming in Java Sachin Malhotra, Chairperson, PGDM-IT, IMS Ghaziabad Saurabh Chaudhary, Dean, Academics, IMS Ghaziabad.
Object Oriented Programming in Java
Object-Orientated Programming
INTRODUCTION TO OOP Objective:
Types of Programming Languages
Inheritance Chapter 7 Inheritance Basics Programming with Inheritance
Inheritance Basics Programming with Inheritance
Object Oriented Theory I
Object oriented vs procedural programming
Testing with OO OO has several key concepts:
Computer Programming with JAVA
Inheritance Chapter 7 Inheritance Basics Programming with Inheritance
Overview of Programming Paradigms
Programming Languages and Paradigms
Object-Oriented PHP (1)
Presentation transcript:

School of Computer Science & Information Technology G6DICP - Lecture 22 The Theory of Object Oriented Programming

2 Programming Methodologies Unstructured Programming Unstructured Programming Procedural Programming Procedural Programming Modular Programming Modular Programming Object Oriented Programming Object Oriented Programming

3 Unstructured Programming The main program consists of statements that directly operates on global data (ie data that is always available). Program main program data

4 Procedural Programming Sequences of statements are combined into one place called a procedure. This can then be invoked as often as needed by the main program. Program main program Procedure

5 Modular Programming Procedures are grouped into modules or libraries. Program Procedure 1 Procedure 2 main program Procedure 3 Module 1

6 Properties of Modular Programming Programs consist of several (sometimes many) interacting parts. Programs consist of several (sometimes many) interacting parts. Libraries can be re-used. Libraries can be re-used. Each module can have its own data, and can manage its own internal state. Each module can have its own data, and can manage its own internal state. Each module exists once in a program, and has a single state. Each module exists once in a program, and has a single state. Management of the state of a module can become complex. Management of the state of a module can become complex.

7 Object Oriented Programming OO programs consist of a web of interacting objects - each with their own state. OO programs consist of a web of interacting objects - each with their own state. Each object is responsible for initialising and destroying itself correctly. Each object is responsible for initialising and destroying itself correctly. This addresses the complexities of modular programming. This addresses the complexities of modular programming. Objects have other attributes that greatly add to the power of manipulating them. Objects have other attributes that greatly add to the power of manipulating them.

8 Object Oriented Languages Pure OO languages Pure OO languages Smalltalk Smalltalk Java Java Impure OO languages Impure OO languages C++ C++ PERL PERL Pascal/Delphi Pascal/Delphi Mixed paradigm languages Mixed paradigm languages Visual Basic Visual Basic JavaScript JavaScript

9 Objects The world is full of objects. The world is full of objects. OO programming was originally developed for the creation of simulations. OO programming was originally developed for the creation of simulations. Because programs ultimately interact with the real world, many (the vast majority) of programming problems can be solved by mapping program code to “objects” that mirror real world objects. Because programs ultimately interact with the real world, many (the vast majority) of programming problems can be solved by mapping program code to “objects” that mirror real world objects.

10 Properties of OO Programming Encapsulation Encapsulation Combining data with the code that acts upon that data to form a new data-type - an object. Combining data with the code that acts upon that data to form a new data-type - an object. Inheritance Inheritance Arranging objects into a hierarchy of descendant objects, with each descendant inheriting access to all of its ancestors code and data. Arranging objects into a hierarchy of descendant objects, with each descendant inheriting access to all of its ancestors code and data. Polymorphism Polymorphism A single action may be used in different ways in different contexts - the implementation of that action being appropriate to the current usage. A single action may be used in different ways in different contexts - the implementation of that action being appropriate to the current usage. Dynamic method binding Dynamic method binding When the compiler can’t determine which method implementation to use in advance the appropriate method is chosen at runtime When the compiler can’t determine which method implementation to use in advance the appropriate method is chosen at runtime

11 Encapsulation Objects model the real world - they are the ultimate form of data abstraction. Objects model the real world - they are the ultimate form of data abstraction. Encapsulation means keeping all of the constituents of an object in the same place. Encapsulation means keeping all of the constituents of an object in the same place. Consider an orange: Consider an orange: Mathematical view - abstracted into separate components (area of skin, weight, fluid volume, number of seeds etc). Mathematical view - abstracted into separate components (area of skin, weight, fluid volume, number of seeds etc). Painters view - encapsulated on canvas an abstract whole. Painters view - encapsulated on canvas an abstract whole. Encapsulation ensures that the relationships between the components of an object are preserved. Encapsulation ensures that the relationships between the components of an object are preserved.

12 Classes In most OO languages encapsulation is implemented by the class. In most OO languages encapsulation is implemented by the class. Java, C++, Object Pascal, and many other programming languages implement OO in this way. Java, C++, Object Pascal, and many other programming languages implement OO in this way. Classes are user-defined data types that encapsulate code (methods) together with data (variables). Classes are user-defined data types that encapsulate code (methods) together with data (variables). Each object is a separate instance of a class, and therefore has its own state. Each object is a separate instance of a class, and therefore has its own state.

13 Inheritance Much of human thought is hierarchical Much of human thought is hierarchical Hierarchies are trees, with a single overall category at the top, and increasing diversity further down. Hierarchies are trees, with a single overall category at the top, and increasing diversity further down. Characteristics are inherited down the hierarchy (ie any daughter category will inherit the properties of its parents). Characteristics are inherited down the hierarchy (ie any daughter category will inherit the properties of its parents). An example is biological taxonomy. An example is biological taxonomy.

14 The Taxonomy of Insects (simplified) Winged InsectsWingless Insects Insects FliesSocial InsectsButterfliesBeetles BeesWaspsAnts

15 Hierarchical Taxonomy Consider Consider How similar is an item to the others of its general class? How similar is an item to the others of its general class? In what ways does it differ from them? In what ways does it differ from them? Each category has a set of behaviours and characteristics that define it. Each category has a set of behaviours and characteristics that define it. The highest levels are the most general (ie the most simple)- lower levels become more specific. The highest levels are the most general (ie the most simple)- lower levels become more specific. Once a characteristic is defined all categories below that in the hierarchy inherit that characteristic Once a characteristic is defined all categories below that in the hierarchy inherit that characteristic

16 Objects: Data structures that inherit (1) Consider a program that handles graphics. Consider a program that handles graphics. We might define a series of classes to draw shapes on the screen. We might define a series of classes to draw shapes on the screen. The top level class is Location The top level class is Location This represents a position on screen This represents a position on screen  Location  X co-ordinate (integer)  Y co-ordinate (integer)

17 Objects: Data structures that inherit (2) If we want to display a pixel we can use a subclass Point. If we want to display a pixel we can use a subclass Point.  Point (subclass of Location)  ( inherited - X co-ordinate )  ( inherited - Y co-ordinate )  visible (boolean)

18 Objects: Data structures that inherit (3) Instances of class point (objects) Instances of class point (objects) firstPoint secondPoint thirdPoint

19 Objects: Data structures that inherit (4) Classes contain data (X co-ordinate, Y co- ordinate and visible), encapsulated with code that operates on that data. Classes contain data (X co-ordinate, Y co- ordinate and visible), encapsulated with code that operates on that data. A method called drawPoint A method called drawPoint  Point (subclass of Location)  ( inherited - X co-ordinate )  ( inherited - Y co-ordinate )  visible (boolean)  drawPoint (method)

20 Objects: Data structures that inherit (5) Methods and variables may be public (ie invoked from anywhere), or private (ie only invoked from other methods in the class) Methods and variables may be public (ie invoked from anywhere), or private (ie only invoked from other methods in the class) A class may have a constructor (a method that is automatically invoked when an instance of the class is created). A class may have a constructor (a method that is automatically invoked when an instance of the class is created). A class may have a destructor (a method that is automatically invoked when an object is destroyed). NB Java does not use destructors! A class may have a destructor (a method that is automatically invoked when an object is destroyed). NB Java does not use destructors!

21 Objects: Data structures that inherit (6)  Point (subclass of Location)  public ( inherited - X co-ordinate )  public ( inherited - Y co-ordinate )  public visible (boolean)  private drawPoint (method)  private deletePoint (method)  public Point (constructor) - calls drawPoint  public togglePoint - calls drawPoint or deletePoint

22 Objects: Data structures that inherit (7) Point may be subclassed as Circle or Square Point may be subclassed as Circle or Square  Circle (subclass of Point)  ( inherited - X co-ordinate )  ( inherited - Y co-ordinate )  ( inherited - visible )  radius - integer  Square (subclass of Point)  ( inherited - X co-ordinate )  ( inherited - Y co-ordinate )  ( inherited - visible )  length of side - integer

23 Objects: Data structures that inherit (8)  Circle (subclass of Point)  ( inherited - X co-ordinate )  ( inherited - Y co-ordinate )  ( inherited - visible )  radius - integer  Circle (constructor)  togglePoint (inherited but overridden)  Square (subclass of Point)  ( inherited - X co-ordinate )  ( inherited - Y co-ordinate )  ( inherited - visible )  length of side - integer Square (constructor)  togglePoint (inherited but overridden)

24 Multiple Inheritance NB This is not implemented in Java! NB This is not implemented in Java! It is implemented in C++ It is implemented in C++ A class may have more than one parent. A class may have more than one parent. PointString Drawable String

25 Polymorphism Although methods are inherited, their behaviour sometimes needs to be modified at different points in the hierarchy. Although methods are inherited, their behaviour sometimes needs to be modified at different points in the hierarchy. The behaviour must be appropriate for the context of use. The behaviour must be appropriate for the context of use. For example - the X,Y coordinates of location could be absolute pixel values or percentages of the screen. A polymorphic method would implement the appropriate functionality. For example - the X,Y coordinates of location could be absolute pixel values or percentages of the screen. A polymorphic method would implement the appropriate functionality. Method overloading is a form of polymorphism. Method overloading is a form of polymorphism.

26 Dynamic Method Binding Where several possible methods are available (eg polymorphic methods) the appropriate method does not need to be indicated to the compiler. Where several possible methods are available (eg polymorphic methods) the appropriate method does not need to be indicated to the compiler. The decision as to which method to use is made at runtime. The decision as to which method to use is made at runtime. In Java, this means that the VM selects the correct method to use at runtime. In Java, this means that the VM selects the correct method to use at runtime.