OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.

Slides:



Advertisements
Similar presentations
1 l Inheritance Basics l Programming with Inheritance l Dynamic Binding and Polymorphism Inheritance.
Advertisements

Inheritance Inheritance Reserved word protected Reserved word super
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.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Object-Oriented PHP (1)
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
Basic OOP Concepts and Terms
1 Chapter 7 l Inheritance Basics l Programming with Inheritance l Dynamic Binding and Polymorphism Inheritance.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
Object-oriented Programming Concepts
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
2-1 © Prentice Hall, 2004 Chapter 2: Introduction to Object Orientation (Adapted) Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra,
Object Oriented Concepts. Movement toward Objects Instead of data-oriented or process-oriented Analysis, many firms are now moving to object-oriented.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
Object-Oriented Analysis and Design
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Chapter 8 More Object Concepts
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
What is inheritance? It is the ability to create a new class from an existing class.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
Advanced Object- Oriented Programming Programming Right from the Start with Visual Basic.NET 1/e 14.
Basic OOP Concepts and Terms. In this class, we will cover: Objects and examples of different object types Classes and how they relate to objects Object.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Object-Oriented Programming. Objectives Distinguish between object-oriented and procedure-oriented design. Define the terms class and object. Distinguish.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Classes, Interfaces and Packages
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
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: Inheritance and Polymorphism.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
An Introduction to Programming with C++ Fifth Edition Chapter 14 Classes and Objects.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Chapter 11 Inheritance © 2008 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved. Marilyn Bohl/Maria Rynn Tools for Structured and Object-Oriented.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Object-Oriented Design
Lecture 12 Inheritance.
Inheritance and Polymorphism
Inheritance Basics Programming with Inheritance
Corresponds with Chapter 7
Computer Programming with JAVA
Inheritance Inheritance is a fundamental Object Oriented concept
Fundaments of Game Design
Basic OOP Concepts and Terms
Object-Oriented PHP (1)
Presentation transcript:

OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560

Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar objects  Instances – specific examples of a particular class  Abstraction – generalized class features; essential facts that distinguish one class from another  Properties (Data or Attributes)  Operations (Methods or Behaviors)

Unified Modeling Language (UML)  UML Class Diagram Class Name  Data Members  Methods  Gradebook Name Grade1 Grade2 Average SetStudent ComputeAverage GetStudent

Encapsulation and Data Hiding  Encapsulation - packaging data members and methods into a single unit (class or instance of a class)  (Public) Interface – well defined external boundary of a class; interact with an object through interface  Data Hiding – related to encapsulation, parts of an object not required to use the object are hidden  Protects code from deliberate or unintended access  Others can use code without understanding how it works  Allows code changes to not affect implementation

Pseudocode Class Gradebook private Name private Grade1 private Grade2 private Average public SetStudent Input Name, Grade1, Grade2 End public ComputeAverage Average = (Grade1 + Grade2)/2 End public GetStudent Display Name, Average End End Class

Data Member and Method Access Levels  Public variables or methods, are those that are visible to all classes.  Private variables or methods, are those that are visible only to the class to which they belong.  Generally all data members are declared as private  Protected variables or methods, are those that are visible only to the class to which they belong, from any subclasses of that class, or from other classes included with the class in a package (a grouping of related classes).

Class and Object Diagrams Gradebook Name Grade1 Grade2 Average SetStudent ComputeAverage GetStudent Gradebook_J001 Name = Bob S. Grade1 = 94 Grade2 = 96 Average = 90 SetStudent ComputeAverage GetStudent Gradebook_J002 Name = Bill P. Grade1 = 76 Grade2 = 84 Average = 80 SetStudent ComputeAverage GetStudent Class Diagram Object Diagram

Driver Programs  Driver programs starts the processing and creates (instantiates) and interacts with (sends messages to) objects Start Gradebook: Gradebook_J001 Gradebook_J001.SetStudent Gradebook_J001.ComputeAverage Gradebook_J001.GetStudent Stop

Constructors  Constructor – method used to instantiate (create) and initialize (set initial data member values) for an object  Default – constructor automatically provided by programming language (e.g. C++ or JAVA). Usually doesn’t initialize data members which may cause problems  Custom – constructor designed to initialize data members. May have more than one for a class.  Have the same name as the class they are constructing  Parameters – data input to a method, including a Constructor

Two Constructor Examples Class Gradebook Public Gradebook Name = “A. Student” Grade1 = 0 Grade2 = 0 Average = 0 End Public Gradebook (Sname, Grd1, Grd1) Name = Sname Grade1 = Grd1 Grade2 = Grd2 Average = 0 End End Class NOTE: I have omitted the data members and other methods from the above

Overloading  The ability to use the same method name to call (invoke) different methods based on the number or type of parameters (inputs)  Can be applied to constructors and other methods  Compare these constructor calls: Gradebook: MyGradebook Gradebook: YourGradebook (“Brian F.”, 95, 84)

Destructors  Destructors are methods used to destroy objects created by constructors  May release (deallocate) memory which had been assigned for an object’s data members  Default Destructor – included by the programming language or Custom Destructor can be written

Other important terms  Return type – the data type of the data returned by a method when it finishes process. You can’t overload a method by using a different return type however as it is not part of the method signature.  Method signature – the general form for describing a method, usually consisting of access modifier, method name, and parameter list (types and order of parameters). (JAVA method signature only contains method name and parameter list) public sample (string, float, float)

Generalization/Specialization  Classes can have relationships with other classes  Generalization/Specialization – one type of relationship  Allows sharing of descriptions and identifications  Used to simplify and shorten implementation tasks  Generally thought of as a requirement for an OOPL  Generalizations – the common features of objects of a particular class  Specializations – the differences between features of objects of a more general class  Two classes have a generalization/specialization relationship: the more specific class is always consistent with the more general class and contains additional information

Inheritance  The mechanism that allows defining a more general class and then later a more specific specialized class by adding new details  The specific class inherits all the properties, methods, and relationships of the general class

Class Hierarchy Employee Name ID Employee GetEmployee SetEmployee DeleteEmployee Faculty Rank Salary Faculty GetEmployee SetEmployee ComputePay Staff Hours Rate Staff GetEmployee SetEmployee ComputePay Superclass (aka base class parent class) Subclasses (aka derived class child class) Indicate a generalization/specialization “is-a” relationship between classes GetEmployee and SetEmployee are overriden from the base class

Polymorphism  Polymorphic method – method with the same name as a method in another class within the same class hierarchy  See ComputePay method on previous slide  Each is unique, neither was inherited  Each calculates pay differently and appropriately  Conceptually, Overloading and Polymorphic Methods are both implementations of Polymorphism (from the Greek for “many forms”)

Classes and Subclasses Class Employee private Name private ID public Employee Name = “A. Employee” ID = End Public GetEmployee * End Public SetEmployee * End Public DeleteEmployee * End End Class* implementation omitted

Classes and Subclasses Class Faculty (base Employee) private Rank private Salary public Faculty Rank = “No rank assigned” Salary = 0 End Public GetEmployee * End Public SetEmployee * End Public ComputePay SWITCHCASE CASE “instructor” Salary = “$35,000” CASE “professor Salary = “$60,000” ENDCASE End End Class* implementation omitted

Abstract and Concrete Classes  Abstract class – one in which one or more of the class methods are identified but not defined  Abstract classes are never instantiated as objects  Declare with keyword “Abstract”  Concrete class – class which is not abstract Abstract Class Account private AccountNumber [rest of class implementation omitted] End Class