CSCI 383 Object-Oriented Programming & Design Lecture 3 Martin van Bommel.

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Advertisements

Design by Contract.
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.
OOP - Object Oriented Programming Object Oriented Programming is an approach to programming that was developed to make large programs easier to manage.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
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.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
Object-Oriented Analysis and Design
CS-2135 Object Oriented Programming
Programming Language Paradigms: summary. Object-oriented programming Objects are the fundamental building blocks of a program. Interaction is structured.
1 SWE Introduction to Software Engineering Lecture 23 – Architectural Design (Chapter 13)
Fall 2007ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
Object-Oriented Thinking Chapter 1, Object-Oriented Programming in Java, Timothy Budd, 1998 ICS102 Semester
Lecture 2 Object Concepts I Object Oriented Analysis and Design K268 SENG2100 Pat Browne
1 Basic Object-Oriented Concepts  Object-Oriented Paradigm What is an Object?  What is a Class?  Constructing Objects from a class Problem Solving in.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
Sharif University of Technology Session # 7.  Contents  Systems Analysis and Design  Planning the approach  Asking questions and collecting data 
INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?
C++ fundamentals.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Introduction to Object-oriented Programming Introduction to Object-oriented Programming CMPS 2143.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
Object Oriented Software Development
CSCI-383 Object-Oriented Programming & Design Lecture 2.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
Objects and Components. The adaptive organization The competitive environment of businesses continuously changing, and the pace of that change is increasing.
An Object-Oriented Approach to Programming Logic and Design
Sadegh Aliakbary Sharif University of Technology Fall 2011.
CONCEPTS OF OBJECT ORIENTED PROGRAMMING. Topics To Be Discussed………………………. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism.
Object Oriented Programming with JAVA Arash N. Kia AlZahra University Definitions – Part 1.
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.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
Objected Oriented Programming & Design JAVA Shishir Gupta (704) (704)
Object-Oriented (Real World Case) Object-Oriented Analysis CIM2566 Bavy LI.
Object Oriented Programming Principles Lecturer: Kalamullah Ramli Electrical Engineering Dept. University of Indonesia Session-3.
CSSE501 Object-Oriented Development. Chapter 11: Static and Dynamic Behavior  In this chapter we will examine the differences between static and dynamic.
CSCI-383 Object-Oriented Programming & Design Lecture 3.
1 OBJECT-ORIENTED THINKING Ziya Karakaya Atılım University Tel: (312) / 5345 Faks: (312) E-posta:
Ceg860 (Prasad)L1SQ1 Software Quality Object-Oriented Programming Paradigm.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Object-Oriented Programming with Java Lecture 1: Introduction Autumn, 2007.
Learners Support Publications 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”
OBJECT ORIENTED AND FUNCTION ORIENTED DESIGN 1 Chapter 6.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Chapter 1: OO Thinking Not just learn Java, but also understand why it is the way it is Learn the OO worldview.
 Computer Science 1MD3 Introduction to Programming Michael Liut Ming Quan Fu Brandon.
1 CMIS301 O-O Thinking Understanding O-O Programming by T Budd.
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
Salman Marvasti Sharif University of Technology Winter 2015.
OOP (Object Oriented Programming) Lecture 1. Why a new paradigm is needed? Complexity Five attributes of complex systems –Frequently, complexity takes.
OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
CSCI 383 Object-Oriented Programming & Design Lecture 7 Martin van Bommel.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
Object Oriented Paradigm OOP’s. Problems with Structured Programming As programs grow ever larger and more complex, even the structured programming approach.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
OOP - Object Oriented Programming
Programming paradigms
Visit for more Learning Resources
OOP What is problem? Solution? OOP
Object-Oriented Programming & Design Lecture 14 Martin van Bommel
Chapter 1: Object-Oriented Thinking
Workshop for Programming And Systems Management Teachers
Presentation transcript:

CSCI 383 Object-Oriented Programming & Design Lecture 3 Martin van Bommel

Fall 2010CSCI 383 Lecture 3 M. van Bommel 2 Imperative Programming So, what are the paradigms of programming? Imperative programming is the “traditional” model of computation State Variables Assignment Loops A processing unit is separate from memory, and “acts” upon memory

Fall 2010CSCI 383 Lecture 3 M. van Bommel 3 Visualization of IP

Fall 2010CSCI 383 Lecture 3 M. van Bommel 4 Recursive Design Why Not Build Program out of Computers? Alan Kay wondered why conventional computers were constructed out of pieces that were useless by themselves Why not build a whole out of pieces that were similar at all levels of detail? (Think of fractals) Idea: A program can be build out of little computing agents

Fall 2010CSCI 383 Lecture 3 M. van Bommel 5 Recursive Design (cont’d) The structure of the part mirrors the structure of the larger unit

Fall 2010CSCI 383 Lecture 3 M. van Bommel 6 Kay's Description of OOP Object-oriented programming is based on the principle of recursive design Everything is an object Objects perform computation by making requests of each other through the passing of messages Every object has its own memory, which consists of other objects Every object is an instance of a class. A class groups similar objects The class is the repository for behavior associated with an object Classes are organized into singly-rooted tree structure, called an inheritance hierarchy We can illustrate these principles by considering how to go about solving a problem in real life

Fall 2010CSCI 383 Lecture 3 M. van Bommel 7 Illustration of OOP Concepts To illustrate the concepts of OOP in an easily understood framework, consider Chris 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) the address for Robin, 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 If we start to think about it, there may even be other people involved in this transaction. There is the flower grower, perhaps somebody in charge of arrangements, and so on

Fall 2010CSCI 383 Lecture 3 M. van Bommel 8 Agents and Communities Our first observation is that results are achieved through the interaction of agents, which we will call objects Furthermore, any nontrivial activity requires the interaction of an entire community of objects working together Each object has a part to play, a service they provide to the other members of the community

Fall 2010CSCI 383 Lecture 3 M. van Bommel 9 Elements of OOP - Objects So we have Kay's first principle Everything is an object Actions in OOP are performed by agents, called instances or objects There are many agents working together in the scenario Chris, Robin, the florist, the florist in Robin’s city, the driver, the flower arranger, and the grower. Each agent has a part to play, and the result is produced when all work together in the solution of a problem

Fall 2010CSCI 383 Lecture 3 M. van Bommel 10 Elements of OOP - Messages And principle number 2: Objects perform computation by making requests of each other through the passing of messages Actions in OOP are produced in response to requests for actions, called messages. An instance may accept a message, and in return will perform an action and return a value To send the flowers, Chris gives a message to Fred. Fred in turn gives a message to the florist in Robin’s city, who gives another message to the driver, and so on

Fall 2010CSCI 383 Lecture 3 M. van Bommel 11 Information Hiding Notice that the user of a service being provided by an object need only know the name of the messages that the object will accept I need not have any idea how the actions performed in response to my request will be carried out Having accepted a message, an object is responsible for carrying it out

Fall 2010CSCI 383 Lecture 3 M. van Bommel 12 Elements of OOP - Receivers Messages differ from traditional function calls in two very important respects: In a message, there is a designated receiver that accepts the message The interpretation of the message may be different, depending upon the receiver

Fall 2010CSCI 383 Lecture 3 M. van Bommel 13 OOP: The General Principle An object oriented program is structured as a community of interacting agents called objects. Action is initiated by the transmission of a message to an agent (an object). The message encodes the request for action and is accompanied by additional information (arguments) needed to carry out the request. The receiver is the agent to which the message is sent. 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.

Fall 2010CSCI 383 Lecture 3 M. van Bommel 14 OOP: A Way to View the World Chris wants to send some flowers to his friend Robin who lives in a distant city. Because of the distance, Chris cannot pick up the flowers and bring them to Robin in person. Chris goes down to Fred, a local florist, and tells him the number and type of flowers he wants together with the address they need to be delivered to. Chris can rest assured that the flowers will be delivered.

Fall 2010CSCI 383 Lecture 3 M. van Bommel 15 Agents, Messages, Methods Chris finds an appropriate agent (Fred) And passes to him a message containing a request It is the responsibility of Fred to satisfy the request There is some method (a set of operations) used by Fred to do this Chris does not need to know the particular method he will use, this information is hidden from inspection

Fall 2010CSCI 383 Lecture 3 M. van Bommel 16 Behavior and Interpretation Although different objects may accept the same message, the actions (behavior) the object will perform will likely be different If Fred asked his wife Beth to send some flowers to Robin for her birthday, she might use a different agent than the florist Fred determination of what behavior to perform may be made at run-time (late binding) The fact that the same name can mean two entirely different operations is one form of polymorphism, a topic we will discuss later

Fall 2010CSCI 383 Lecture 3 M. van Bommel 17 OOP Element - Recursive Design Every object has its own memory, which consists of other objects Each object is like a miniature computer itself - a specialized processor performing a specific task

Fall 2010CSCI 383 Lecture 3 M. van Bommel 18 Non-interference It is important that objects be allowed to perform their task however they see fit, without unnecessary interactions or interference with other objects “Instead of a bit-grinding processor... plundering data structures, we have a universe of well-behaved objects that courteously ask each other to carry out their various desires” -- Dan Ingalls “Ask not what you can do to your data structures, but ask what your data structures can do for you”

Fall 2010CSCI 383 Lecture 3 M. van Bommel 19 Elements of OOP - Classes Every object is an instance of a class. A class groups similar objects The class is the repository for behavior associated with an object The behavior I expect from Fred is determined from a general idea I have of Florists We say Fred is an instance of the class Florist Behavior is associated with classes, not with individual instances. All objects that are instances of a class use the same method in response to similar messages

Fall 2010CSCI 383 Lecture 3 M. van Bommel 20 Hierarchies of Categories But there is more that I know about Fred than just that he is a Florist. I know he is a ShopKeeper, and a Human, and a Mammal, and a Material Objects, and so on At each level of abstraction I have certain information recorded. That information is applicable to all lower (more specialized) levels

Fall 2010CSCI 383 Lecture 3 M. van Bommel 21 Elements of OOP - Inheritance The principle that knowledge of a more general category is also applicable to a more specific category is called inheritance Classes can be organised into a hierarchical inheritance structure. A child class (subclass) will inherit attributes from a parent class (super class) higher up in the hierarchy. An abstract parent class is a class for which there are no direct instances, it is only introduced to group subclasses

Fall 2010CSCI 383 Lecture 3 M. van Bommel 22 Hierarchies of Categories

Fall 2010CSCI 383 Lecture 3 M. van Bommel 23 Class Hierarchies

Fall 2010CSCI 383 Lecture 3 M. van Bommel 24 Elements of OOP - Overriding Subclasses can alter or override information inherited from parent classes: All mammals give birth to live young A platypus is an egg-laying mammal The search for a method to use in response to a message starts with the receiver’s class and continues up the parent chain. When methods with the same name are available higher in the class hierarchy the method that executes is said to override the inherited behavior Inheritance combined with overriding are where most of the power of OO originates

Fall 2010CSCI 383 Lecture 3 M. van Bommel 25 Problem Solving Because the OOP view is similar to the way in which people go about solving problems in real life (finding another agent to do the real work!), intuition, ideas, and understanding from everyday experience can be brought to bear on computing However, infinite recursion does not solve the problem Someone has to do the work! On the other hand, common sense was seldom useful when computers were viewed in the process-state model, since few people solve their everyday problems using pigeon-holes

Fall 2010CSCI 383 Lecture 3 M. van Bommel 26 From Newsweek “Unlike the usual programming method – writing software one line at a time – NeXT's ‘object-oriented’ system offers larger building blocks that developers can quickly assemble the way a kid builds faces on Mr. Potato Head.”