Object–Orientated Design. OOP Design Describe the following: a computer a university Usually the most natural way to describe a task is to list the entities.

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

OOP: Inheritance By: Lamiaa Said.
OOP - Object Oriented Programming Object Oriented Programming is an approach to programming that was developed to make large programs easier to manage.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
You gotta be cool. Inheritance Base Classes and Derived Classes Inheritance: Public, Protected, Private What is inherited from the base class? Multiple.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CS-2135 Object Oriented Programming
Fall 2007CS 2251 Inheritance and Class Hierarchies Chapter 3.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 1 Introduction to Object-Oriented Programming and.
HST 952 Computing for Biomedical Scientists Lecture 2.
Chapter Chapter 1 Introduction to Object-Oriented Programming and Software Development.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Lecture 1 Introduction to Computers and Object-
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 1 Introduction to Object-Oriented Programming.
Object-Orientated Design and Programming Unit 9: Abstract Classes and Interfaces Jin Sa.
Modelling classes Drawing a Class Diagram. Class diagram First pick the classes –Choose relevant nouns, which have attributes and operations. Find the.
Lilian Blot INHERITANCE Object Oriented Programming Spring 2014 TPOP 1.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Specialization and generalization
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 1 Introduction to Object-Oriented Programming and.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Database Systems Lecture # 7 8 th Feb, Conceptual and Logical Design Person buys Product name pricenamessn Conceptual Model: Relational Model: (plus.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Object Oriented Programming Concepts. Object Oriented Programming Type of programming whereby the programmer defines the data types of a data structure.
CS212: Object Oriented Analysis and Design Lecture 13: Relationship between Classes.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class.
© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Chapter 1 Introduction to 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”
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Computer Science Projects Internal Assessment. Mastery Item Claimed Justification Where Listed Random Access File – Searching Lines P. 53 Random.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
Object Oriented Programming
Exam 1 Review Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
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.
Exam 1 Review Dr. Bernard Chen Ph.D. University of Central Arkansas.
Creating Classes from Other Classes Appendix D © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
April 20022/CS/3X EER 1 Database Design Enhanced entity-relationship modelling John Wordsworth Department of Computer Science The University of Reading.
Class Diagram Lecture # 1. Class diagram A Class Diagram is a diagram describing the structure of a system shows the system's classes Attributes operations.
1 ODB Design Handling Inheritance in ODL M. Akhtar Ali School of Informatics.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
OOP - Object Oriented Programming
Inheritance Chapter 7 Inheritance Basics Programming with Inheritance
Reuse Separate classes could be developed for all the different objects that are needed in each program. However that would be wasteful. Often many functionalities.
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING
Final and Abstract Classes
Week 4 Object-Oriented Programming (1): Inheritance
Road Map Inheritance Class hierarchy Overriding methods Constructors
Object-oriented programming
Object Oriented Programming (OOP) LAB # 8
Domain Class Diagram Chapter 4 Part 2 pp
Chapter 10 Thinking in Objects
MSIS 670 Object-Oriented Software Engineering
topics object oriented design objects and classes properties
OBJECT ORIENTED PROGRAMMING
Object Oriented Analysis and Design
Final and Abstract Classes
OBJECT ORIENTED PROGRAMMING
Computer Science II for Majors
Presentation transcript:

Object–Orientated Design

OOP Design Describe the following: a computer a university Usually the most natural way to describe a task is to list the entities involved in the task. These entities are referred to as objects.

OOP Design Objects Objects in general have two important properties: 1. State 2. Behaviour

OOP Design Object States An object contains certain information about itself: e.g. a lecturer “knows” their name, address, age, courses they teach etc. a student “knows” their name, address, age, ID, courses studied etc. a lecture theatre “knows” its location, capacity etc.

OOP Design The information that an object maintains determines its state. The individual components of information are known as the objects attributes. The attributes of an object may be “primitive” values such as integers, characters etc. e.g. a lecturer’s name, a student’s ID

OOP Design The attributes of an object may also be other objects. e.g. a computer may have memory as an attribute but memory may also be an object within the system. The attributes of memory could include capacity, type etc. Object Behaviour Apart from maintaining information about itself an object is also capable of performing certain actions.

OOP Design e.g. a lecturer can teach a class, mark assignments, set an examination paper a student can attend a lecture, complete an assignment, sit an exam etc. The actions that an object can perform are known as its behaviours. When applying an object-orientated design to a problem specification we identify objects, record their states and specify their behaviour.

OOP Design Instances and Classes Generally we can distinguish between two types of object: 1. An instance 2. A class

OOP Design Instances Instances correspond to individual entities in the application of interest: e.g. a lecturer called “Mr Jones” a student called “Cathy Smith”

OOP Design Classes Classes correspond to classes or templates of an entity: e.g. lecturer is a class computer is a class student is a class Each instance in a system must be an instance of some class.

OOP Design e.g. Mr Jones is an instance of a lecturer Cathy Smith is an instance of a student Definition of an Object An object must be an instance of some class. A class describes the type of information and behaviour that an object can have while an object contains specific information for each attribute in its class.

OOP Design Super-Classes Looking closely at our lecturer and student classes it is clear there is some similarity between the states of lecturers and students. e.g. teachers and students “know” their names, addresses and ages In object-orientated design we can specify a super-class that contains all the attributes and behaviours that are common between classes.

OOP Design Consider the super-class person. The attributes of the person class could be: Name Address Age The behaviour of the person class could be: Telling name Telling address Telling age

OOP Design Now the lecturer and student classes are sub-classes of the person super-class. All sub-classes inherit the properties of their super-classes. An instance of a sub-class is also automatically an instance of its super-class. A super-class can also be a sub-class of another super-class etc.

OOP Design This sub-class super-class relationship can lead to a class or inheritance hierarchy. Example Applicance Machine VehicleComputer VanCarTruck MiniDeliveryLimoSportsDumpPickup

OOP Design An object is not only a member of the class it is an instance of; it is also a member of any of its super-classes, as well as a member of any of the super-classes super-classes etc. This argument also applies to sub-classes; not only is a class a sub-class of its super-class but a sub-class of the super-classes super-classes. e.g. a pickup is also a truck, a vehicle and a machine.

OOP Design Each sub-class is said to inherit the state and behaviour of its super-classes i.e. we specify common states and behaviours once in a super-class which any sub-class can then inherit.

OOP Design Behaviour Overriding Problem: A shape class contains the length of two dimensions and the behaviour calculate_area as attributes. Three sub- classes of this class are defined as Square, Rectangle and Triangle. Square Shape RectangleTriangle

OOP Design The calculate_area behaviour returns the area of the shape by multiplying one dimension by the other. What problem arises with this class hierarchy ? The inherited behaviour calculate_area will provide an incorrect answer for an object of class Triangle.

OOP Design To overcome this problem we can remove the common behaviour from the class shape and incorporate separate behaviours in all three sub-classes Square, Rectangle and Triangle. Each sub-class class can contain the same behaviour named calculate_area. This is known as polymorphism. This method is perfectly legal but there is some duplication in behaviour particularly between the Rectangle and Square classes.

OOP Design Fortunately Object-Orientated Design provides a more efficient and natural way to overcome this problem. A subclass can override the behaviour defined in a super- class i.e. if a specific behaviour is defined in a class as well as its super-class then the class behaviour takes priority. e.g. the generic behaviour calculate_area can be inherited by the Square and Rectangle classes but we can override the calculate_area behaviour in the Triangle class.