Review of object Orientation Lecturer: Dr. Mai Fadel.

Slides:



Advertisements
Similar presentations
Introduction to Object Orientation System Analysis and Design
Advertisements

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.
Solutions to Review Questions. 4.1 Define object, class and instance. The UML Glossary gives these definitions: Object: an instance of a class. Class:
Classes & Objects Computer Science I Last updated 9/30/10.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
Introduction To System Analysis and Design
Object-Oriented PHP (1)
Review of OO Introduction to Eclipse/Java September 6, 2005.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 2: Review of Object Orientation.
More about inheritance Exploring polymorphism. 02/12/2004Lecture 8: More about inheritance2 Main concepts to be covered method polymorphism static and.
Chapter 14 (Web): Object-Oriented Data Modeling
Chapter 10 Classes Continued
Object-oriented design CS 345 September 20,2002. Unavoidable Complexity Many software systems are very complex: –Many developers –Ongoing lifespan –Large.
Sharif University of Technology Session # 7.  Contents  Systems Analysis and Design  Planning the approach  Asking questions and collecting data 
Chapter 14: Object-Oriented Data Modeling
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 2: Review of Object Orientation 1.
Introduction To System Analysis and design
© Lethbridge/Laganière 2005 Chapter 2: Review of Object Orientation1 Warm Up Question: Draw a Pert diagram for the following tasks: TaskPreceding TaskDescriptionDuration.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented Design.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Programming Languages and Paradigms Object-Oriented Programming.
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.
Basic Concepts Introduction to OO Development and Software Engineering Principles SYSC System Analysis and Design.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Lecture 9 Polymorphism Richard Gesick.
CHAPTER ONE Problem Solving and the Object- Oriented Paradigm.
Introduction To System Analysis and Design
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.
Chapter 9 Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design.
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 13 (Online): Object-Oriented Data Modeling Modern Database Management 10 th Edition.
Object-Oriented Programming. An object is anything that can be represented by data in a computer’s memory and manipulated by a computer program.
Programming in Java CSCI-2220 Object Oriented Programming.
Object Oriented Software Development
Object-Oriented Data Modeling
 All calls to method toString and earnings are resolved at execution time, based on the type of the object to which currentEmployee refers.  Known as.
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Object-Oriented Programming Chapter Chapter
M1G Introduction to Programming 2 5. Completing the program.
Object Oriented Programming
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
CSE 143 Lecture 12 Inheritance slides created by Ethan Apter
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.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Polymorphism and Inheritance (CS-319 Supplementary Notes)
CSCE 240 – Intro to Software Engineering Lecture 3.
ISBN Chapter 12 Support for Object-Oriented Programming.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 2: Review of Object Orientation.
Chapter 11 Object-Oriented Design
Object Oriented Programming
Lecture 23 Polymorphism Richard Gesick.
Lecture 22 Inheritance Richard Gesick.
Fundaments of Game Design
Object-Oriented PHP (1)
Final and Abstract Classes
Chapter 2: Review of Object Orientation
Presentation transcript:

Review of object Orientation Lecturer: Dr. Mai Fadel

What is Object Orientation? Object-oriented systems make use of abstraction in order to help make software less complex Abstraction: a representation that captures only essential aspects of something, reducing the complexity apparent to the abstraction’s user Object-oriented systems combine procedural and data abstraction

What is Object Orientation?- Procedural Paradigm Software has been organized around the notion of procedures (functions/routines) A programmer does not need to worry about all the details of how it performs its computation focus on how to call the procedure and what it computes The entire system is organized into a set of procedures with one ‘main’ procedure calls several other procedures Works well for performing calculations with relatively simple data Become complex if each procedure works with many types of data, or if each type of data has many different procedures that access and modify it

What is Object Orientation? - Data Abstraction Records and structures were the first data abstractions to be introduced To group together the pieces of data that describe some entity, so that programmers can manipulate that data as a unit Problems: –complex code in many different places –Implementation of common rules would be scattered throughout the code making change very difficult

Data abstraction – Banking example Design: a hierarchy of procedures + records representing banking accounts Functionality: –Manage accounts of different types, such as checking/current, savings, mortgage accounts –Each type of account will have different rules for computation of fees, interest, etc. –Different account holders might have different rights Problems –Frequent problematic pseudo codes –Rules scattered throughout the code

The Object-Oriented Paradigm Organizing procedural in the context of data abstractions The root of Object-oriented (OO) paradigm is to putt all the procedures that access or modify a particular class of objects in one place Definition The Object-oriented paradigm is an approach to the solution of problems in which all computations are performed in the context of objects. The objects are instances of programming constructs, normally called classes, which are data abstractions and which contain procedural abstractions that operate on the objects A running system can be seen as a collection of objects collaborating to perform a given task

ProceduralObject-oriented

Classes and Objects Object: can represent anything with which you can associate properties and behaviour –Properties characterize the object, describing its current state –Behaviour is the way an object acts and reacts, possibly changing its state –e.g. an example of a banking system

Payroll system: an employee University registration program: student, course, faculty Factory automation system: assembly line, each robot, each item, type of product

Classes and their instances Classes: are the units of data abstraction in an object- oriented program All the objects with the same properties and behaviour are instances of one class Class Employee declares that all its instances have a name, a dateOfBirth, an address, and a position A class contains all of the code that relates to its objects, including –Code describing how the objects of the class are structured- i.e. the data stored in each object that implement the properties –The procedures, called methods, that implement the behaviour of the object. Employee name dateOfBirth address position

Example 2.1 & Exercise Examples of classes and instances –Film –Reel of film –Film reel with serial number SW19876 –Showing of ‘Star Wars’ in Phoenix Cinema at 7 pm Exercise –General Motors –Game –Automobile Company –The game of chess between Tom and Jane which started at 2:30 pm yesterday

Naming Classes How to name a class? Important conventions to help the reader differentiate between what is class & what is not –First Letter Capital –Written in Singular (a single Item not a list) –More than one name: Bumpy capitals, e.g. PartTimeEmployee –Meaning: neither too general nor too specific –Name classes after the thing their instances represent –Avoid using words that reflect the internals of a computer systems. e.g. ‘Record’, ‘Structure’,’Data’ –Refer to pp

Exercise Not good names for classes in a scheduling system of a passenger rail company –Train- Stop- SleepingCareData- arrive- Routes- driver- SpecialTrainInfo Identify all classes that might be part of the following systems –A restaurant reservation system –A video rental store

Instance Variables (IV)s - A variable is a place where you can put data. - IVs are the list of variables of a class that will be present in each instance - IVs are used to implement attributes or associations Attributes An attribute is a piece of data used to represent the properties of an object e.g. Employee: name, dateOfBirth, socialSecurityNumber, telephoneNumber, address Associations An association represents the relationship between instances of one class and instances of another e.g. Employee –Manager (supervisor) –Task (tasksToDo)

Instance Variables (IV)s Var. vs. Objects: A variable is often called a reference when it refers to an object A class variable/ static variable is created to hold a value that is shared by all instances of a class –Usually used to define ‘constant’ values, and lookup tables used by algorithms inside a particular class Identify the attributes –Passenger (in an airline system) –PhoneCall (in the system of a mobile phone company)

Methods, Operations and Polymorphism Method ≈ procedure, function, or routine in programs Methods are procedural abstractions used to implement the behaviour of a class An operation is used to discuss and specify a type of behaviour, independently of any code that implements that behaviour (higher abstraction) Polymorphic operation is an operation that changes its behaviour during run-time. The program decides which of several identically named methods to invoke. Polymorphism is a property of OO software by which an abstract operation may be performed in different ways, typically in different classes e.g. computing the Perimeter of a rectangular, & a square

Organizing Classes into inheritance Hierarchies If several classes have attributes, associations, or operations in common, it is best to avoid duplication by creating a separate superclass that contains these common aspects. If you have a complex class, it may be good to divide its functionality among several specialized subclasses A generalization is the relationship between a subclass and its immediate superclass A hierarchy with one or more generalizations is called an inheritance hierarchy/ generalization hierarchy/ isa hierarchy

Inheritance Inheritance is the implicit possession by a subclass of features defined in a superclass. Features include variable and methods Inheritance automatically occurs The isa rule: class A can only be a valid subclass of class B if it makes sense, in English, to say ‘an A is a B’ 3 checks pp Careful generalizations and their resulting inheritance hierarchies help to avoid duplication and improve reuse Diagram form Textual form Account SavingAcc CurrentAcc MortgageAcc Account SavingsAccCurrentAccMortgageAcc

MathematicalObject ShapePointMatrix Shape2DShape3D EllipsePolygon CircleQuadrilateral Rectangle PlaneLine Example 2.2: Organize the following set of classes into hierarchies: Circle, Point, Rectangle, Matrix, Ellipse, Line, Plane EllipseShape Ellipse focus1 focus2 Circle center

The Effect of Inheritance on Polymorphism and Variable Declarations

Much of the power of the OO paradigm comes from polymorphism and inheritance working together Figure 2.8: four-level hierarchy, leaf classes (pp )

The Effect of Inheritance on Polymorphism..- Abstract classes and abstract methods rotate operation found in Shape2D class is an abstract operation. Why? p. 47 –No method for that operation exists in the class –Has logical meaning in class –Abstract operations are shown in italics –You have abstract operations anywhere except leaf classes Shape2D, EllipticalShape, Polygon, SimplePolygon, must be abstract classes. Why? p. 47 –It cannot have any instances –Any class except leaf classes can be declared abstract –The class that has one or more abstract methods must be declared abstract –The main purpose of an abstract class is to hold features that will be inherited by its subclasses –If a class is not abstract it is called concrete –In concrete classes, instances can be created, all leaf classes must be concrete, it is possible to have concrete classes at higher-levels The implementation of abstract operations is completed by the time we reach the leaf classes. The implementation can be distributed along the hierarchy from superclass till leaf class ( rotate in SimplePolygon ) More details in p.48

The Effect of Inheritance on Polymorphism..- Overriding The implementation of getBoundingRect() in Rectangle overrides the implementation of the same operation in Polygon Three reasons for overriding: –Restriction: the overriding method prevents a violation of a certain constraints that are present in the subclass, but were not present in the superclass. It can have some undesirable effects p.49 It is important to ensure that all polymorphic methods implementing an abstract operation behave consistently –Extension: the overriding method does basically the same thing as the version in the superclass, but adds some extra capability needed in the subclass –Optimization: the overriding method in thesubclass has exactly the same effect as the overridden method, except that it is more efficient.

The Effect of Inheritance on Polymorphism..- Variable & Dynamic binding Declaring a variable of a superclass means that as the program runs, the variable can contain objects of any concrete class in the hierarchy. If you attempt to invoke a polymorphic operation on the variable, the program will make the decision about what method to run ‘on the fly’. Dynamic binding/ late binding/ virtual binding is the decision-making process. The procedure used to perform dynamic binding p.50 For efficiency an optimized approach using a lookup table is used instead Dynamic binding is only needed when the compiler determines that there is more than one possible method that could be executed by a particular call

Dynamic binding –exercise In which of the following would dynamic binding be needed? Variable of type invoke the operation Rectangle getPerimeterLength SimplePolygon getCentre Polygon getBoundingRect