Sadegh Aliakbary Sharif University of Technology Fall 2011.

Slides:



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

Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
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.
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 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.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
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.
C++ fundamentals.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Abstraction: Polymorphism, pt. 1 Abstracting Objects.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
 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.
Object Oriented Software Development
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Writing Classes (Chapter 4)
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
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 Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
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.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
S.Ducasse Stéphane Ducasse 1 Object-Oriented Programming.
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.
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”
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
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.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
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.
Copyright 2006 Oxford Consulting, Ltd1 January Introduction to C++ Programming is taking A problem Find the area of a rectangle A set of data.
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
Copyright 2005, The Ohio State University CSE – Introduction to C++ Name: Shirish Tatikonda Time: T 3:30 PM Room: BE 394
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.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 26, 2009.
Topic 4: Distributed Objects Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine.
Object-Oriented Programming Concepts
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
Object Oriented Programming F3031
JAVA Introduction ការណែនាំពី Java
Anatomy of a Class & Method
Computer Programming.
Advanced Programming in Java
Advanced Programming Behnam Hatami Fall 2017.
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 2011

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 2011Sharif University of Technology2

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 2011Sharif University of Technology3

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 2011Sharif University of Technology4

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 2011Sharif University of Technology5

Library Problem Suppose you want to write a library program What are the elements of your program? We think about functions and variables… Fall 2011Sharif 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 2011Sharif 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 2011Sharif 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 2011Sharif 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 2011Sharif 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 2011Sharif 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 2011Sharif University of Technology12

Everything is an object 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; 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. Fall 2011Sharif 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 2011Sharif 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 2011Sharif 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 2011Sharif 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 2011Sharif 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 (may) have internal data which gives it state An object (may) 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 2011Sharif 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 2011Sharif 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 2011Sharif 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 2011Sharif University of Technology21

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

Person in an Education System Fall 2011Sharif University of Technology23

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

Encapsulation Commercial products are encapsulated Remote control TV Cell phone They are Black Boxes Hidden Implementations Public interface Fall 2011Sharif 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 2011Sharif 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 2011Sharif 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 2011Sharif University of Technology28

Example: Rectangle Lets encapsulate a rectangle What is a rectangle? An object Which has length and width (properties) Lets you specify its length and width Can calculate its area and perimeter Fall 2011Sharif University of Technology29

public class Rectangle { private int width, length; public void setWidth(int w) { width = w; } public void setLength(int l) { length = l; } public int calculateArea(){ return width*length; } public int calculatePerimeter(){ return (width+length)*2; } Fall 2011Sharif University of Technology30 Private area: hidden implementation Public area : the interface Class Declaration

How to Use Rectangle? Rectangle rect = new Rectangle(); rect.setWidth(2); rect.setLength(7); System.out.println(rect.calculateArea()); System.out.println( rect.calculatePerimeter() ); Fall 2011Sharif University of Technology31 Object creation or instantiation

More Exercises Encapsulate these concepts: Student Footbal-Player Dog name, age : properties bite, bark : messages (actions) Fall 2011Sharif University of Technology32

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 2011Sharif University of Technology33

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 2011Sharif University of Technology34

Fall 2011Sharif University of Technology35