Fundamental Concepts (Principles) of Object Oriented Programming These slides are based on:

Similar documents
Introduction and Review of Java: Part 2

Object-oriented perspective

CITS2210. Object-Oriented Programming. Topic 1. Introduction and Fundamentals: Thinking Object-Oriented

Object Oriented Programming עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון

CHAPTER 5 GENERAL OOP CONCEPTS

Object oriented programming Concepts

Chapter 5 Object-Oriented Programming

Object- Oriented Design with UML and Java Part I: Fundamentals

Elementary Concepts of Object Class

Object-Oriented Programming in C++/Handout 01 Page 1 of 8

Chapter 8: Class and Method Design

Programmazione. Prof. Marco Bertini

OBJECT ORIENTED SYSTEM DEVELOPMENT Software Development Dynamic System Development Information system solution Steps in System Development Analysis

Underlying computer system = hardware + software

Chapter 1: Programming Principles

Goals of the Lecture OO Programming Principles

Chapter 1: Principles of Programming and Software Engineering

1. Write two major differences between Object-oriented programming and procedural programming?

Object-Oriented Programming

Module Outline. What is Object-Oriented? Some Possible Definitions. Why Object-oriented? Fundamentals of Object Orientation

What are the characteristics of Object Oriented programming language?

Object Orientated Analysis and Design. Benjamin Kenwright

Lecture 1. Abstraction

Software Development. Modular Design and Algorithm Analysis

BASIC CONCEPT OF OOP

CSIT 2008 June 28, 2008 Anita Verno, Bergen Community College,

THE OBJECT-ORIENTED DESIGN PROCESS AND DESIGN AXIOMS (CH -9)

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module

Object Oriented Programming using C++

Software Design Heuristics

Object-Oriented Modeling Using UML. CS151 Chris Pollett Aug. 29, 2005.

Inheritance (Outsource: )

Static and Dynamic Behavior לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון

The Essence of Object Oriented Programming with Java and UML. Chapter 2. The Essence of Objects. What Is an Object-Oriented System?

What is a Programming Paradigm

Relationships amongst Objects

Computer Science 32 Object-Oriented Oriented Design and Implementation (in C++ on Linux)

Object Oriented Programming

The object-oriented approach goes a step further by providing tools for the programmer to represent elements in the problem space.

RDD and Strategy Pa.ern

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

2. Classes & Inheritance. Classes. Classes. Éric Tanter Objects and Design in Smalltalk. How do you create objects?

UML & OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 3 08/30/2011

Abstraction. Abstraction

Object-Oriented Programming Paradigm

Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson

CSE 70 Final Exam Fall 2009

C++ Classes & Object Oriented Programming

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Static and Dynamic Behavior עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מובסס על הרצאות של אותו קורס שניתן בשנים הקודמות ע "י ד"ר גרא וייס

Object-Oriented Design

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Components vs. Objects

What is Inheritance?

Object-Oriented Design

An Introduction to Software Architecture By David Garlan & Mary Shaw 94

9.1 OO Methodology OO Design Object

More OO Fundamentals. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 4 09/11/2012

Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page:

Part 7 - Object Oriented Concepts Classes, Objects, Properties and Methods

CAS 703 Software Design


Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 2: Review of Object Orientation

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Software Design and Analysis for Engineers

Object Oriented Software Design

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Classes, Objects, and OOP in Java. June 16, 2017

Object-Oriented Programming in LotusScript Bill Buchan HADSL

What is Object-Oriented Programming

Object Oriented Programming

Information Hiding and Aspect-Oriented Modeling

CS504-Softwere Engineering -1 Solved Objective Midterm Papers For Preparation of Midterm Exam

CGS 2405 Advanced Programming with C++ Course Justification

Inheritance CSC 123 Fall 2018 Howard Rosenthal

Inheritance and Substitution גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Object-Oriented Design

Example: Fibonacci Numbers

Programming in C# Inheritance and Polymorphism

A STUDY OF OBJECT ORIENTED ANALYSIS AND DESIGN


C++ Important Questions with Answers

An Overview of Visual Basic.NET: A History and a Demonstration

Introduction. Object-Oriented Programming Spring 2015

Programming II. Modularity 2017/18

Technical Metrics for OO Systems

Inheritance and Polymorphism

Object-Oriented Technology. Rick Mercer

JAVA: A Primer. By: Amrita Rajagopal

1: Introduction to Object (1)

Object Oriented Programming

UML & OO Fundamentals. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 3 09/04/2012

Object Oriented Paradigm

Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page:

C++ Programming: Introduction to C++ and OOP (Object Oriented Programming)

OBJECT ORIENTED PROGRAMMING

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Java OOP (SE Tutorials: Learning the Java Language Trail : Object-Oriented Programming Concepts Lesson )

Appendix A - Glossary(of OO software term s)


Transcription:

1 Fundamental Concepts (Principles) of Object Oriented Programming These slides are based on: [1] Timothy A. Budd, Oregon State University, Corvallis, Oregon, [Available] ClickMe, September 2001.

2 What is Object Oriented Programming? OOP was invented to mitigate the increasing complexity of software trying to make software simpler and more manageable. The Object Oriented approach is to view software the same way we view the world easier for us to understand. OOP is a way of thinking about how to create computer programs to solve problems Everything is an object, and objects communicate between each other and collaborate to implement tasks. Consider how we might go about handling a real-world situation and then ask how we could design software to do the same.

3 Illustration Of OO Concepts Sending Flowers to a Friend Consider the problem of sending flowers to a friend who lives in a different city. Chris is sending flowers to Robin. Chris can t deliver them directly. So Chris uses the services of the local Florist. Chris tells the Florist (named Fred) Robin s address, how much to spend, and the type of flowers to send. Fred contacts a florist in Robin s city, who arranges the flowers, then contacts a driver, who delivers the flowers.

4 Community of Agents (Objects) Helping Deliver Flowers Chris Fred:Florist Robin sflorist :Wholesaler :Grower :Gardener Robin :DeliveryPerson :FlowerArranger UML Instance Diagram

5 Object Interaction An object oriented program is structured as a community of interacting agents, called objects. Each object has a role to play. Each object provides a service, or performs an action, that is used by other members of the community.

6 Messages and Methods The chain reaction that ultimately resulted in the solution to Chris s problem began with a request given to the florist Fred. This request lead to other requests, which lead to still more requests, until the flowers ultimately reached Chris s friend Robin.

Messages and Methods Action is initiated in by the transmission of a message to an agent (an object). The message encodes the request for an action and may be accompanied by any additional information (arguments) needed to carry out the request. If the receiver accepts the message, it accepts the responsibility to carry out the indicated action. In response to a message, the receiver will perform some method to satisfy the request. 7

8 Object Protocol Each agent has responsibilities that it can do requests that it can fill out Set of responsibilities is called the object s protocol. An object s protocol is the set of methods (responsibilities and behavior) it can do and knows how to do, and the set of responses it can and will send back to the requestor in response to a request to perform a behavior.

Information Hiding and 9 Abstraction A receiving agent does not need to advertise or inform the requesting agent how the request will be implemented For example, Fred will not tell Chris how he intends to deliver the flowers, and whether there will be intermediaries involved, horse and buggy, planes, etc. This gives Fred flexibility to implement his methods without the interference from Chris. This results in simpler systems because there is less coupling between objects. Chris s world is simpler because he does not take on the burden on worrying how the request will be implemented. Fred s world is simpler because he does not need to follow Chris s view of how a request should be implemented, if Chris were to specify one.

10 Polymorphism A receiving agent can implement a request differently. For example, on one hand, Fred may implement Chris delivery request by sending a message to Robin s florist. On the other hand, Robin s florist, may send a message to the delivery person to send the flowers to Robin. Furthermore, perhaps Fred has multiple ways of implementing the same delivery request, and he chooses the best one according to the situation. This gives Fred flexibility to implement his methods in his own optimal way. It may be too expensive for Fred to deliver the flowers directly to Robin; it could be more efficient to contract Robin s florist to do so. If the flowers were to be delivered to a destination near Fred s business, then Fred may choose to deliver the flowers himself by car/bicycle. Different receiving agents may implement a request in different ways.

11 Reusable Components If there is a task to perform, the first thought of the client is to find somebody else he or she can ask to do the work. For example, Fred may not know an efficient way of delivering the flowers to a foreign country. Instead of learning how to do this, Fred will choose to rely on the experience of others who have been doing this in the past and are very efficient at it. Instead of the client inventing the method to do the work, it is natural to look for some other object that can do the work, that has the experience in doing it, and is trusted to do it properly. This concept is one of Building on the Experience of Others When reusable components are used, the software becomes more reliable, less complex for the individual agents, and quicker to develop.

12 Classes of Objects Agents of the same type are similar, and they may be classified as a class Although Chris has only dealt with Fred a few times, Chris has a rough idea of the transaction that will occur inside Fred's flower shop. Chris is able to make certain assumptions based on previous experience with other florists, and hence Chris can expect that Fred, being an instance of this category, will fit the general pattern. Other Florists, like Jane, Samantha, and Fernando Other Gardeners, etc. Class for Florists, Gardeners, Delivery Person, etc.

13 Inheritance Hierarchy Each class can be organized into a hierarchy Chris knows, for example, that a transfer of money will be part of the transaction, and that in return for payment Fred will offer a receipt. These actions are true of grocers, stationers, and other shopkeepers. Fred is a Florist, Florist is Shopkeeper, Shopkeeper is a Human, Human is a Mammal, Mammal is an Animal, Animal is a Material Object. Classes inherit properties of upper layer classes

Categories Surrounding Fred MaterialObject Animal Mammal Human Shopkeeper Florist Non-standard Diagram UML Class Diagram (Showing Inheritance) 14

15 A Class Inheritance Hierarchy UML Class Diagram MaterialObject Animal Plant Mammal Flower Dog Human Platypus Carnation Shopkeeper Artist Dentist Florist Potter

16 Principles of Object-oriented (OO) Programming 1. Everything is an object An object-oriented program is structured as a community of interacting agents, called objects. Each object has a set of responsibilities (behavior), a set of things it can do. Each object has a role to play and provides a service, or performs an action, that is used by other members of the community.

17 Principles of Object-oriented (OO) Programming 2. Objects send messages (requests) to one another Action is initiated in object-oriented programming by sending a message to an object responsible for the action. Messages are usually implemented as methods, a way in which a request is implemented. Additional information is encoded in the argument list of the method, if required. In response, the receiver will perform some method to satisfy the request.

18 Principles of Object-oriented (OO) Programming 3. All objects are instances of a class Objects of similar type are grouped into a class Objects within the same class will implement methods in the same way, and they will also have the same set of features (variables)

19 Principles of Object-oriented (OO) Programming 4. Encapsulation Encapsulation is the packing of state (variables) and behavior (methods) into a single component (object). An object should have full control over its state and how it implements its behavior. It enforce protecting variables, functions from outside of class. Everything that belongs to objects of a certain class should be included in the class, and everything else should be left out.

20 Principles of Object-oriented (OO) Programming 5. Information Hiding and Abstraction The implementation of an object s methods are hidden from external view This means the system will be more flexible for change and optimization, and will also be simpler, because there will be less coupling between classes.

21 Principles of Object-oriented (OO) Programming 6. Class Hierarchies Classes may be organized in an inheritance hierarchy, where higher layers contain more general information and lower layers contain more specific information about the class. Lower layer classes in the hierarchy inherit properties of higher layer classes in the hierarchy.

Principles of Object-oriented (OO) Programming 7. Method Binding The search for a method to invoke in response to a given message begins with the class of the receiver. If no appropriate method is found, the search is conducted in the parent class of this class. The search continues up the parent class chain until either a method is found and executed If a method is not found, an error message is issued. 22

23 Principles of Object-oriented (OO) Programming 8. Reuse and Reusable Components Reusing components increases reliability and quality. Building on the experience of others. Some characteristics that make software more easily reusable are modularity, loose coupling, high cohesion, information hiding and separation of concerns.

24 Principles of Object-oriented (OO) Programming 9. Polymorphism Different receiving agents may implement a request in different ways. This gives objects flexibility to implement methods in their own optimal way.