Sadegh Aliakbary Sharif University of Technology Fall 2010.

Slides:



Advertisements
Similar presentations
When is Orientated Programming NOT? Mike Fitzpatrick.
Advertisements

Advanced Programming in Java Peyman Dodangeh Sharif University of Technology Fall 2013 Lecture 1: Introduction to OOP Slides adapted from Steven Roehrig.
CMSC 202 Fall 2010, Advanced Section Designing with Objects.
Solutions to Review Questions. 4.1 Define object, class and instance. The UML Glossary gives these definitions: Object: an instance of a class. Class:
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
1 Software Testing and Quality Assurance Lecture 12 - The Testing Perspective (Chapter 2, A Practical Guide to Testing Object-Oriented Software)
Object Oriented Programming A brief review of what you should know about OOP.
Object Oriented System Development with VB .NET
What is an object? Your dog, your desk, your television set, your bicycle. Real-world objects share two characteristics: They all have state and behavior;
Stéphane Ducasse6.1 Essential Concepts Why OO? What is OO? What are the benefits? What are the KEY concepts? Basis for all the lectures.
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
Object Oriented Programming The object concept. Alan Kay—Smalltalk—5 basic characteristics of OOP 1.Everything is an object. An object is a fancy variable-it.
Object Oriented Concepts. Movement toward Objects Instead of data-oriented or process-oriented Analysis, many firms are now moving to object-oriented.
C++ fundamentals.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Introduction to Object-oriented Programming Introduction to Object-oriented Programming CMPS 2143.
 Computer Science 1MD3 Introduction to Programming Michael Liut Ming Quan Fu Brandon.
Object Oriented Programming
CPT 140 Programming Constructs1 OBJECT ORIENTED TECHNOLOGY Terminology and Basic Concepts.
Introduction To System Analysis and design
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
BCS 2143 Introduction to Object Oriented and Software Development.
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
JAVA Introduction ● One of the main JAVA design goal is reducing complexity for programmer – Development time is half or less comparing to equivalent C++
Introduction to Objects Adapted from “TEN STEPS TO OBJECT-SPEAK” a CPT Tech Talk by Joy Starks September 17, 1999.
SE-1010 Dr. Mark L. Hornick 1 Introduction to Object-Oriented Programming (OOP) Part 1.
Sadegh Aliakbary Sharif University of Technology Fall 2012.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Objected Oriented Programming & Design JAVA Shishir Gupta (704) (704)
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Salman Marvasti Sharif University of Technology Fall 2014.
Object Oriented Programming Principles Lecturer: Kalamullah Ramli Electrical Engineering Dept. University of Indonesia Session-3.
OOP Class Lawrence D’Antonio Lecture 3 An Overview of C++
SNPL1 Woochang Lim What (Variable) + How (Function) = Object Objects are the physical and conceptual things we find in the universe around us. Object-Oriented.
Object-Oriented Design Simple Program Design Third Edition A Step-by-Step Approach 11.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Object-Oriented Programming with Java Lecture 1: Introduction Autumn, 2007.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Abstraction ADTs, Information Hiding and Encapsulation.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Basic Concepts of Object Orientation Object-Oriented Analysis CIM2566 Bavy LI.
Salman Marvasti Sharif University of Technology Winter 2015.
S.Ducasse Stéphane Ducasse 1 Essential OO Concepts Stéphane Ducasse.
OOP (Object Oriented Programming) Lecture 1. Why a new paradigm is needed? Complexity Five attributes of complex systems –Frequently, complexity takes.
Introduction to OOP Mehdi Einali Advanced Programming in Java 1.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
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.
Copyright 2006 Oxford Consulting, Ltd1 January Introduction to C++ Programming is taking A problem Find the area of a rectangle A set of data.
Introduction To OOP 1.0 Fundamentals Of Java Programming Language 2.0 Exception Handling 3.0 Classes, Inheritance And Polymorphism © 2011 | PN AZRINA.
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
Introduction to OOP Mehdi Einali Advanced Programming in Java 1.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Topic 4: Distributed Objects Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine.
Programming paradigms
Object-Oriented Programming Concepts
Sections Basic Concepts of Programming
Object Oriented Concepts -I
JAVA Introduction ការណែនាំពី Java
Anatomy of a Class & Method
Computer Programming.
Advanced Programming in Java
Advanced Programming Behnam Hatami Fall 2017.
Programming Languages 2nd edition Tucker and Noonan
Introduction to Data Structure
The OOTP is intended to get you thinking about how OO concepts are used in designing object-oriented systems. Note: not talking about OO technologies that.
Presentation transcript:

Sadegh Aliakbary Sharif University of Technology Fall 2010

Agenda Object Oriented Programming Characteristics of objects Interface Encapsulation The notes are mainly extracted from TIJ book Codes of this slide are pseudocodes they may have syntactic or logical errors Fall 2010Sharif University of Technology2

Library Problem Suppose you want to write a library program What are the elements of your program? We think about functions and variables… Fall 2010Sharif University of Technology3

Abstraction Machine language Assembly: an abstraction of the machine language Many languages are abstraction of assembly language Fortran, Basic, C Big improvement But they still require you to think in terms of the structure of the computer. Rather than the structure of the problem. Fall 2010Sharif University of Technology4

Different Contexts Problem Space the place where the problem exists such as a business Solution Space the place where you’re implementing that solution such as a computer The effort required to perform this mapping. E.g. think about a library, or a phonebook program Name problem space and solution space entities. Fall 2010Sharif University of Technology5

Alternatives to model the machine An alternative is to model the problem Some early languages chose particular views of the world: LISP  All problems are ultimately lists APL  All problems are algorithmic Prolog  Casts all problems into chains of decisions. Languages have been created for constraint-based programming Each of these approaches may be a good for particular class of problems But not for all problems… Fall 2010Sharif University of Technology6

Object Oriented Approach OO approach goes a step further Lets the programmer represent problem space elements This representation is general enough The programmer is not constrained to any particular type of problem. The elements in the problem space and their representations in the solution space are referred to as “objects” Fall 2010Sharif University of Technology7

OOP The program is allowed to adapt itself to the lingo of the problem by adding new types of objects when you read the code, you’re reading words that also express the problem. This is a more flexible and powerful language abstraction Fall 2010Sharif University of Technology8

OOP (2) OOP allows you to describe the problem in terms of the problem Rather than in terms of the computer Objects in your code are similar to real objects Recall the sample programs: phonebook and library Fall 2010Sharif University of Technology9

Object Oriented Languages Smalltalk The first successful object-oriented language One of the languages upon which Java is based Java C++ C## Fall 2010Sharif University of Technology10

OOP vs. Procedural Approach Elements of OOP Objects Message passing between objects Elements of procedural programming Functions Variables Function invocation The way of thinking Thinking about objects and relations Thinking about functions and computer structure Fall 2010Sharif University of Technology11

OOP Characteristics Alan Kay summarized five basic characteristics of Smalltalk 1. Everything is an object 2. A program is a bunch of objects telling each other what to do by sending messages 3. Each object has its own memory made up of other objects 4. Every object has a type 5. All objects of a particular type can receive the same messages Fall 2010Sharif University of Technology12

Everything is an object Think of an object as a variable It stores data But you can make requests to that object asking it to perform operations on itself. You can take any conceptual component in the problem dogs, buildings, services, … And represent it as an object in your program. Example int number; Person p; Book book; Fall 2010Sharif University of Technology13

Object Messages To make a request of an object, you send a message to that object. Message = invoking a method of an object. Example Book b; if(b.isReserved())… Person p; p.setPhoneNumber( ) Fall 2010Sharif University of Technology14

Each object has its own memory You can create a new kind of object by making a package containing existing objects Thus, you can build complexity into a program while hiding it behind the simplicity of objects Book{ String name; Person reservedTo; } Fall 2010Sharif University of Technology15

Every object has a type Each object is an instance of a class class is synonymous with type The most important distinguishing characteristic of a class is What messages can you send to it? Person p; Person q; Person[] people; Fall 2010Sharif University of Technology16

Substitutability All objects of a particular type can receive the same messages An object of type circle is also an object of type shape A circle is guaranteed to accept shape messages You can write code that talks to shapes and automatically handle anything that fits the description of a shape. This substitutability is one of the powerful concepts in OOP. Inheritance Polymorphism Fall 2010Sharif University of Technology17

Booch’s description of an Object An object has state, behavior and identity Booch has added identity to the description. An object (can) have internal data which gives it state An object (can) have methods to produce behavior And each object can be uniquely distinguished from every other object Each object has a unique address in memory. Fall 2010Sharif University of Technology18

Abstract Data Types Each programming language has some predefined data types int, double, char, … Creating abstract data types is a fundamental concept in object-oriented programming Abstract Data Type = Class Programmer defines a class to fit a problem You extend the programming language by adding new data types specific to your needs Fall 2010Sharif University of Technology19

Messages E.g. Assign a book to a person Set phone number of a person Calculate area of a shape complete a transaction draw something on the screen turn on a switch. Fall 2010Sharif University of Technology20

Interface Each object can satisfy only certain requests The requests you can make of an object are defined by its interface The type is what determines the interface. Fall 2010Sharif University of Technology21

Representation of a light bulb: Fall 2010Sharif University of Technology22 UML Diagram

Person in an Education System Fall 2010Sharif University of Technology23

New names in OOP Function  Method, Service Variable  Property, State Fall 2010Sharif University of Technology24

Encapsulation Commercial products are encapsulated Remote control TV Cell phone They are Black Boxes Hidden Implementations Public interface Fall 2010Sharif University of Technology25

Why Encapsulation? Simplified use Even for the producer Open implementation  bad use Hiding the implementation reduces bugs It is more beautiful! Fall 2010Sharif University of Technology26

Object Encapsulation Encapsulation of a problem-space concept into a class of objects Define interface Hide the implementation Black box The client may see the implementation But can not use it directly This is better even for the producer (programmer) Fall 2010Sharif University of Technology27

Access Control Access to some parts of the class is restricted Public and Private area of the class The client of a class can use only public area Public area = class interface Public methods Public variables Fall 2010Sharif University of Technology28

Exercise Lets encapsulate a rectangle Write a java code… Fall 2010Sharif University of Technology29

Conclusion OOP brings us a new abstraction OOP allows you to describe the problem in terms of the problem Think in terms of the structure of the problem Rather than the structure of the computer Object has state, behavior and identity Object has data and interface Fall 2010Sharif University of Technology30

Further Reading Google these queries and read some pages (Wikipedia is preferred) Object Oriented Programming History of Object Oriented Programming Smalltalk UML Encapsulation Inheritance Polymorphism Fall 2010Sharif University of Technology31

Quiz! Write a java class for representing … Fall 2010Sharif University of Technology32

Fall 2010Sharif University of Technology33