DEV-08: Exploring Object-oriented Programming

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
OpenEdge® Object-oriented ABL
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
ITEC200 – Week03 Inheritance and Class Hierarchies.
1 Software Testing and Quality Assurance Lecture 12 - The Testing Perspective (Chapter 2, A Practical Guide to Testing Object-Oriented Software)
Object-Oriented PHP (1)
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.
Object-oriented Programming Concepts
Chapter 10 Classes Continued
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
UML and Object Oriented Concepts
BACS 287 Basics of Object-Oriented Programming 1.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Eclipse – making OOP Easy
Introduction to Object-oriented programming and software development Lecture 1.
Objects and Components. The adaptive organization The competitive environment of businesses continuously changing, and the pace of that change is increasing.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
Object Oriented Design and Programming Alan Goude Room: Sheaf 9323.
Object-oriented programming in the Progress® 4GL 10.1A Beta
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Unified Modeling Language, Version 2.0
Object-Oriented Programming and the Progress ABL Tomáš Kučera Principal Solution Engineer / EMEA Power Team.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
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.
DEV-6: Advanced Object-Oriented Programming in the ABL Evan Bleicher Senior Development Manager Shelley Chase
Object Oriented Programming
1 Unified Modeling Language, Version 2.0 Chapter 2.
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
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Basic Characteristics of Object-Oriented Systems
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Slide 1 Unified Modeling Language, Version 2.0 Object-Oriented SAD.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Object Oriented Systems Design
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Object-Oriented Programming
Design Patterns: MORE Examples
Object-Oriented Design
Programming paradigms
Sections Inheritance and Abstract Classes
Object Oriented Programming
The Movement To Objects
CHAPTER 5 GENERAL OOP CONCEPTS.
Systems Analysis and Design With UML 2
Inheritance and Polymorphism
Chapter 11 Object-Oriented Design
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Object Oriented Analysis and Design
Lecture 22 Inheritance Richard Gesick.
More Object-Oriented Programming
Object-Oriented Programming: Inheritance and Polymorphism
Fundaments of Game Design
Object Oriented Analysis and Design
Object-Oriented PHP (1)
Agenda Software development (SD) & Software development methodologies (SDM) Orthogonal views of the software OOSD Methodology Why an Object Orientation?
C++ Object Oriented 1.
UML  UML stands for Unified Modeling Language. It is a standard which is mainly used for creating object- oriented, meaningful documentation models for.
Presentation transcript:

DEV-08: Exploring Object-oriented Programming Shelley Chase Development Architect – Progress OpenEdge

Today’s Agenda Basic Principles of Object-oriented Programming Types, Classes, Objects, and Interfaces Inheritance, Polymorphism, and Delegation DEV-08, Exploring Object-oriented Programming

What are Objects? You interact with objects everyday A customer An order All objects contains state and behavior What they can do and what changes when they do Software objects represent these as: Data ( like 4GL variables ) Methods ( like 4GL procedures) Your car The telephone DEV-08, Exploring Object-oriented Programming

Object-oriented Programming “Object-oriented programming is a method of implementation in which programs are organized as cooperative collections of objects, each of which represents an instance of some class...” Grady Booch DEV-08, Exploring Object-oriented Programming

Object-oriented Application Development A way to design and build applications Objects bundle together data (state) and methods (behavior) Objects facilitate separating definition from implementation Much more than just syntax You might have already done object-oriented programming in the 4GL DEV-08, Exploring Object-oriented Programming

Designing an Object-oriented Application Object: Order Take an Order Object: Customer Check Credit Create a Customer Object: beOrder Assign Salesperson Progress DataSet Customer Table Order Table Customer Table DEV-08, Exploring Object-oriented Programming

Basic Object-oriented Principles Abstraction Encapsulation Hierarchies DEV-08, Exploring Object-oriented Programming

Abstraction Abstraction is used to manage complexity Public View of an Object Abstraction is used to manage complexity Focus on the essential characteristics Eliminate the details Find commonalities among objects Defines the public contract Public definition for users of the object The “Outside view” Independent of implementation DEV-08, Exploring Object-oriented Programming

“What should an Order object do?” Abstraction - Example “What should an Order object do?” Object: Order CreateOrder UpdateOrder GetOrderTotal Next InternalOrder Two types of Orders ExternalOrder DEV-08, Exploring Object-oriented Programming

Encapsulation Encapsulation hides implementation Hide Implementation Details Encapsulation hides implementation Promotes modular software design – data and methods together Data access always done through methods Often called “information hiding” Provides two kinds of protection: State cannot be changed directly from outside Implementation can change without affecting users of the object DEV-08, Exploring Object-oriented Programming

Encapsulation - Example Implementation Outside View Object: Order orderNum AS INT custNum AS INT CalculatePrice( ) PUBLIC: CreateOrder( ) UpdateOrder( ) GetOrderTotal( ) Next( ) Public methods of Order class CreateOrder UpdateOrder GetOrderTotal Next CreateOrder( ) UpdateOrder( ) GetOrderTotal( ) Next( ) DEV-08, Exploring Object-oriented Programming

Encapsulation - Example continued Hmm... I’d like to change CalculatePrice to CalculateTotalPrice Object: Order orderNum AS INT custNum AS INT CalculatePrice( ) PUBLIC: CreateOrder( ) UpdateOrder( ) GetOrderTotal( ) Next( ) GetOrderTotal calls CalculatePrice( ) DEV-08, Exploring Object-oriented Programming

Encapsulation - Example continued Object: Order This change was easy because users of the object will not be affected. orderNum AS INT custNum AS INT CalculateTotalPrice( ) PUBLIC: CreateOrder( ) UpdateOrder( ) GetOrderTotal( ) Next( ) GetOrderTotal now calls CalculateTotalPrice( ) DEV-08, Exploring Object-oriented Programming

Hierarchies Define relationships between objects Object Relationships Define relationships between objects Objects defined in terms of other objects Allows state and behavior to be shared and specialized as necessary Encourages code reuse Two important hierarchy types: Inheritance Aggregation DEV-08, Exploring Object-oriented Programming

Hierarchies - Example Order is a is a references InternalOrder Order uses ShipInfo (Aggregation) Order is a is a references InternalOrder ExternalOrder ShipInfo InternalOrder and ExternalOrder inherit from Order (Inheritance) DEV-08, Exploring Object-oriented Programming

Summary : Object-oriented Principles Abstraction Break up complex problem Focus on public view, commonalities Encapsulation Hide implementation details Package data and methods together Hierarchies Build new objects by combining or extending other objects DEV-08, Exploring Object-oriented Programming

Today’s Agenda Basic Principles of Object-oriented Programming Types, Classes, Objects, and Interfaces Inheritance, Polymorphism, and Delegation DEV-08, Exploring Object-oriented Programming

Type A Type defines the state and behavior Enables strong-typing A Type is a definition A Type defines the state and behavior Identifies inheritance relationships with other types No concern for implementation Enables strong-typing Early binding - types determined at compile time Type-consistency enforced at compile time and runtime DEV-08, Exploring Object-oriented Programming

Type - Example Types: Order Order InternalOrder ExternalOrder is a Subtype of Order ExternalOrder SubType of Order Order is a is a InternalOrder ExternalOrder A subtype can appear anywhere a super type is expected DEV-08, Exploring Object-oriented Programming

Benefits of Types (Strong-Typing) Compile time checking for type consistency myObj = mySubObject. (must be subType) myObj:method(…). (validates signature) myObj:data = 3. (validates data type) Results in safer, bug-free code because all code paths checked at compile time DEV-08, Exploring Object-oriented Programming

Class Class: Order A Class defines and implements a user-defined type A Class implements a Type Class: Order orderNum AS INT custNum AS INT CalculateTotalPrice( ) PUBLIC: CreateOrder( ) UpdateOrder( ) GetOrderTotal( ) Next( ) A Class defines and implements a user-defined type A Class is a template (blueprint) for an object: Data Methods Relationships to other classes Methods Data DEV-08, Exploring Object-oriented Programming

Object An Object is created at runtime An Object is an instance of a Class An Object is created at runtime Maintains independent state in data members Code shared among object instances The term Object is often used to refer to both classes and instances MyOrder orderNum = 10 custNum = 3 Total Price = $45.00 YourOrder orderNum = 61 custNum = 58 Total Price = $318.34 DEV-08, Exploring Object-oriented Programming

Interface An Interface implements a Type An Interface is a collection of method definitions for a set of behaviors – a “contract” No implementation provided A Class can implement an interface Must implement all methods in the interface Behavior can be specialized Compiler validates implementation of interface DEV-08, Exploring Object-oriented Programming

Interface - Example Class Order implements IList interface orderNum AS INT custNum AS INT CalculateTotalPrice( ) PUBLIC: CreateOrder( ) UpdateOrder( ) GetOrderTotal( ) Next( ) Interface: IList PUBLIC: Next( ) Compiler checks for method definition in implementing class DEV-08, Exploring Object-oriented Programming

Interface – Example continued Write generic routine using interface MoveNext( listObj AS IList ) listObj.Next( ). /* Calls method in real object */ Call with any object that implements IList myOrder = NEW Order( ). /* implements IList */ MoveNext( myOrder ). or myCust = NEW Customer( ). /* implements IList */ MoveNext( myCust ). DEV-08, Exploring Object-oriented Programming

Benefits of Interfaces Allows many different classes to be treated in a like manner All classes that implement an interface are guaranteed to have same set of methods Enables generic programming IList example allows any collection of objects to be navigated using Next( ) Behavior can be specialized as needed DEV-08, Exploring Object-oriented Programming

Summary : Object-oriented Constructs Type Enforces type consistency at compile time Class Defines type with data and methods and provides implementation Object Runtime instantiation of class Interface Defines type with methods – no implementation provided DEV-08, Exploring Object-oriented Programming

Today’s Agenda Basic Principles of Object-oriented Programming Types, Classes, Objects, and Interfaces Inheritance, Polymorphism, and Delegation DEV-08, Exploring Object-oriented Programming

Inheritance Super Class (Base class) Subclass (Derived class) Relationship between Classes Super Class Super Class (Base class) Provides common functionality and data members Subclass (Derived class) Inherits public and protected members from the super class Can extend or change behavior of super class by overriding methods … Subclass DEV-08, Exploring Object-oriented Programming

Access Levels for Class Members PRIVATE members available: Only within the class PROTECTED members available: Within the class Within the class hierarchy PUBLIC members available: To users outside the class Order PRIVATE PROTECTED PUBLIC DEV-08, Exploring Object-oriented Programming

Inheritance Example Class: Order PRIVATE: orderNum AS INT custNum AS INT CalculateTotalPrice( ) PROTECTED: GetCredit( ) PUBLIC: CreateOrder( ) UpdateOrder( ) GetOrderTotal( ) Next( ) DEV-08, Exploring Object-oriented Programming

Class InternalOrder inherits Order Inheritance Example Class InternalOrder inherits Order Class: Order PRIVATE: orderNum AS INT custNum AS INT CalculateTotalPrice( ) InternalOrder PROTECTED: GetCredit( ) PUBLIC: CreateOrder( ) UpdateOrder( ) GetOrderTotal( ) Next( ) PROTECTED: GetCredit( ) PUBLIC: CreateOrder( ) UpdateOrder( ) GetOrderTotal( ) Next( ) PROTECTED: GetCredit( ) PUBLIC: CreateOrder( ) UpdateOrder( ) GetOrderTotal( ) Next( ) DEV-08, Exploring Object-oriented Programming

Inheritance and Method Overriding Method overriding used to specialize behavior Subclass may override a method in its super class (hierarchy) Method signatures must match Overriden method can: Completely override behavior of super class Augment behavior by providing its own behavior and calling super class method DEV-08, Exploring Object-oriented Programming

Method Overriding – Example 1 Order PROTECTED: GetCredit( ) credit = FindCreditScore( ). Class InternalOrder inherits Order InternalOrder PROTECTED: GetCredit ( ) credit = -1. /*unlimited*/ DEV-08, Exploring Object-oriented Programming

Method Overriding – Example 2 Order PROTECTED: GetCredit( ) credit = CalculateCredit( ). Class ExternalOrder inherits Order ExternalOrder PROTECTED: GetCredit( ) credit = SUPER:GetCredit( ) + extraMoney. DEV-08, Exploring Object-oriented Programming

Benefits of Inheritance and Overriding Inheritance supports modular design Common behavior put in super class and used by subclass Subclass can override to specialize behavior Inheritance is strongly-typed InternalOrder myOrder = NEW InternalOrder. myOrder.GetCredit( ). myOrder knows it is an InternalOrder DEV-08, Exploring Object-oriented Programming

Polymorphism One interface, many implementations Execution of an overridden method in a subclass from a reference to a super class superclass:method( ) Code written using super class Tightly coupled to inheritance and overriding Super class used at compile time, subclass assigned at runtime Method call on super class dispatched to subclass’ method at runtime DEV-08, Exploring Object-oriented Programming

Polymorphism – Example Order PROTECTED: GetCredit( ) credit = CalculateCredit( ). InternalOrder ExternalOrder PROTECTED: GetCredit ( ) credit = -1. /*unlimited*/ PROTECTED: GetCredit( ) credit = SUPER:GetCredit( ) + extraCreditPoints. DEV-08, Exploring Object-oriented Programming

Polymorphism – Example continued DEFINE myOrder AS Order. if (bInternalCust = TRUE) myOrder = NEW InternalOrder( ). else myOrder = NEW ExternalOrder( ). myOrder:GetCredit( ). Super Class reference Calls InternalOrder:GetCredit( ) or ExternalOrder:GetCredit( ) DEV-08, Exploring Object-oriented Programming

Benefits of Polymorphism Supports generic programming using super class or interface Type used at compile time is super class or interface Specialized behavior is called at runtime automatically Built on inheritance and overriding DEV-08, Exploring Object-oriented Programming

Delegation Delegation is the use of other objects within a class Class forwards method calls to the contained object Class wraps the delegate object Creates an instance of the object Defines a “stub” method for any referenced methods that should be public No access to protected or private members DEV-08, Exploring Object-oriented Programming

Class Order references a ShipInfo object Delegation – Example Class Order references a ShipInfo object Order PRIVATE: ShipInfo shipObj = NEW ShipInfo( ) PUBLIC: GetShipDate( ) shipObj:GetDate( ) ShipInfo PRIVATE: id shipdate promisedate PUBLIC: SetDate( ) GetDate( ) … calls DEV-08, Exploring Object-oriented Programming

Benefits of Delegation Delegation supports modular design Purposed class does work Class uses delegate to provide needed functionality Class can determine what to put in API With inheritance super class dictates API; with delegation wrapper class decides what to expose DEV-08, Exploring Object-oriented Programming

That’s Object-oriented Programming What did we learn… DEV-08, Exploring Object-oriented Programming

Terminology / Concept Review Abstraction – Public API Encapsulation – Hide implementation details Hierarchy – Relationships between classes Strong-typing – Type consistency enforced Class – Data members and methods Object – Runtime instance of a class Interface – Set of method definitions; contract Inheritance – Inherit/specialize from super class Polymorphism – Most-derived method called from super class reference Delegation – Other objects do the work DEV-08, Exploring Object-oriented Programming

Benefits of OO Programming Promotes modular design Data and methods that operate on that data are contained in one place Commonalities put into super classes Code reuse through hierarchies Inheritance and delegation Strong-typing Compile-time type checking Runtime type checking DEV-08, Exploring Object-oriented Programming

Recommended OO Books Object-Oriented Analysis and Design with Applications (2nd Edition) by Grady Booch Object-Oriented Modeling and Design by James R Rumbaugh… Design Patterns, Elements of Reusable Object-oriented Software by Erich Gamma… DEV-08, Exploring Object-oriented Programming

**Attend Session DEV-10 for details In Summary Object-oriented programming is more than syntax – must be part of design Many benefits in OO Programming Can be combined with procedural programming, not all or nothing OpenEdge™ 10.1 Language enhancements support object-oriented programming naturally **Attend Session DEV-10 for details DEV-08, Exploring Object-oriented Programming

Questions? DEV-08, Exploring Object-oriented Programming

Thank you for your time! DEV-08, Exploring Object-oriented Programming

DEV-08, Exploring Object-oriented Programming