1 G54PRG Programming Lecture 1 Amadeo Ascó Adam Moore 20 Object Oriented Theory II.

Slides:



Advertisements
Similar presentations
Overriding CMPS Overriding Recall, a method in a child class overrides a method in the parent class, if it has the same name and type signature.
Advertisements

Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
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.
OOP: Inheritance By: Lamiaa Said.
CS 211 Inheritance AAA.
C++ Inheritance Gordon College CPS212. Basics OO-programming can be defined as a combination of Abstract Data Types (ADTs) with Inheritance and Dynamic.
Department of computer science N. Harika. Inheritance Inheritance is a fundamental Object Oriented concept A class can be defined as a "subclass" of another.
More about classes and objects Classes in Visual Basic.NET.
Inheritance The objectives of this chapter are: To explore the concept and implications of inheritance Polymorphism To define the syntax of inheritance.
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.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation - a language mechanism for restricting access to some.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Inheritance and Polymorphism CS351 – Programming Paradigms.
CSSE501 Object-Oriented Development
BACS 287 Basics of Object-Oriented Programming 1.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
CONCEPTS OF OBJECT ORIENTED PROGRAMMING. Topics To Be Discussed………………………. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
School of Computer Science & Information Technology G6DICP - Lecture 22 The Theory of Object Oriented Programming.
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 With Java ICS201 University Of Ha’il1 Chapter 8 Polymorphism and Abstract Classes.
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
Programming With Java ICS Chapter 8 Polymorphism.
Inheritance in the Java programming language J. W. Rider.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
Object-Oriented Programming. An object is anything that can be represented by data in a computer’s memory and manipulated by a computer program.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
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:
1 OOP - An Introduction ISQS 6337 John R. Durrett.
Object Oriented Programming
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
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.
CSCI-383 Object-Oriented Programming & Design Lecture 24.
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.
OBJECT ORIENTED PROGRAMMING. Design principles for organizing code into user-defined types Principles include: Encapsulation Inheritance Polymorphism.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
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.
Introduction to Object Oriented Programming Lecture-3.
CSC 205 Programming II Lecture 4 Abstract Class. The abstract keyword indicate that a class is not instantiable Defining a type which will be specialized.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Inheritance ITI1121 Nour El Kadri.
Object-Oriented Analysis and Design
Object Oriented Programming in Java
Types of Programming Languages
12 Data abstraction Packages and encapsulation
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
Inheritance Basics Programming with Inheritance
Support for Object-Oriented Programming in Ada 95
Object oriented vs procedural programming
Testing with OO OO has several key concepts:
Computer Programming with JAVA
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Programming in C# CHAPTER 5 & 6
Presentation transcript:

1 G54PRG Programming Lecture 1 Amadeo Ascó Adam Moore 20 Object Oriented Theory II

2 Amadeo Ascó, Adam Moore Previously Programming Methodologies – Unstructured Programming – Procedural Programming – Modular Programming Properties of Modular Programming – Object Oriented Programming Object Oriented Languages Objects

3 Amadeo Ascó, Adam Moore Overview Properties of OO Programming Encapsulation Classes The Taxonomy of Insects Hierarchical Taxonomy Objects – Data Structures that Inherit Multiple Inheritance Polymorphism Dynamic Method Binding

4 Amadeo Ascó, Adam Moore Properties of OO Programming Encapsulation – Combining data with the code that acts upon that data to form a new data-type - an object. Inheritance – Arranging objects into a hierarchy of descendant objects, with each descendant inheriting access to all of its ancestors code and data. Polymorphism – 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

5 Amadeo Ascó, Adam Moore Encapsulation 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. Consider an orange: – Mathematical view - abstracted into separate components (area of skin, weight, fluid volume, number of seeds etc). – Painters view - encapsulated on canvas an abstract whole. Encapsulation ensures that the relationships between the components of an object are preserved.

6 Amadeo Ascó, Adam Moore Classes In most OO languages encapsulation is implemented by the class. 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). Each object is a separate instance of a class, and therefore has its own state.

7 Amadeo Ascó, Adam Moore The Taxonomy of Insects

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

9 Amadeo Ascó, Adam Moore Objects – Data Structures that Inherit (1) Consider a program that handles graphics. We might define a series of classes to draw shapes on the screen. The top level class is Location This represents a position on screen Location X co-ordinate (integer) Y co-ordinate (integer)

10 Amadeo Ascó, Adam Moore Objects – Data Structures that Inherit (2) 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)

11 Amadeo Ascó, Adam Moore Objects – Data Structures that Inherit (3) Instances of class point (objects) Point 1 Point 3 Point 2

12 Amadeo Ascó, Adam Moore 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. A method called drawPoint Point (subclass of Location) ( inherited -X co-ordinate ) ( inherited -Y co-ordinate ) visible (boolean) drawPoint (method)

13 Amadeo Ascó, Adam Moore Objects – Data Structures that Inherit (5) Methods and variables may be public (i.e. invoked from anywhere), or private (i.e. 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 destructor (a method that is automatically invoked when an object is destroyed). N.B. Java does not use destructors!

14 Amadeo Ascó, Adam Moore 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 togglePointcalls drawPoint or deletePoint

15 Amadeo Ascó, Adam Moore Objects – Data Structures that Inherit (7) 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 )

16 Amadeo Ascó, Adam Moore 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)

17 Amadeo Ascó, Adam Moore Multiple Inheritance N.B. This is not implemented in Java! It is implemented in C++ A class may have more than one parent String Drawable String Point

18 Amadeo Ascó, Adam Moore Polymorphism 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. 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.

19 Amadeo Ascó, Adam Moore Dynamic Method Binding Where several possible methods are available (e.g. 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. In Java, this means that the VM selects the correct method to use at runtime.