(a very brief) introduction to objects

19
(a very brief) Introduction to Objects by Dr. Billy B. L. Lim

Upload: steve

Post on 14-Jan-2016

30 views

Category:

Documents


3 download

DESCRIPTION

(a very brief) Introduction to Objects. by Dr. Billy B. L. Lim. # of attendees at OOPSLA/JavaOne continues to increase Products continue to surface in the market OO Languages: C++, Smalltalk, Java , Eiffel, Objective-C, CLOS, Turbo Pascal, Ada 9X, OO Turing, Object-COBOL, etc. OO 4GLs: - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: (a very brief)  Introduction to Objects

(a very brief) Introduction to Objects

by Dr. Billy B. L. Lim

Page 2: (a very brief)  Introduction to Objects

Why Object-Orientation: Observation # of attendees at OOPSLA/JavaOne

continues to increase Products continue to surface in the market

– OO Languages:o C++, Smalltalk, Java, Eiffel, Objective-C, CLOS, Turbo

Pascal, Ada 9X, OO Turing, Object-COBOL, etc.– OO 4GLs:

o PowerBuilder, Enfin, ObjectView, etc.– ORDBMSs/OODBMSs:

o Oracle 10g, DB2 Viper, SQL Server 2005, etc.o ObjectStore, Gemstone, Versant, Ontos, OpenODB,

Trellis, O2, Orion, etc.– Class Libraries

o MFC, OWL, Tools.h++, etc.

Page 3: (a very brief)  Introduction to Objects
Page 4: (a very brief)  Introduction to Objects

What is an Object?

1. a thing that can be seen or touched 2. a person or thing to which action, feeling,

etc. is directed ... [Webster's 87] Objects are an attempt to associate more

meaning with data Data and code together form objects Code associated with an objects (called methods)

define its behavior and provides services An encapsulation of state (data values) and

behavior (operations) [Budd 91] People, places, and things (PPT)

Page 5: (a very brief)  Introduction to Objects

An "Object" in C

/* This is a struct in C */

struct Student { char* ssn; char* name; float gpa; char* major; };

struct Student s1, s2;

Page 6: (a very brief)  Introduction to Objects

An Object in Java

class Student {/* State */private String name;private String address;private float gpa;private String major;/* Behavior */

public void print() {

System.out.println("Name ="+ name);// print other attributes here }

}

Student s = new Student() ;

creates an object of type Student

Page 7: (a very brief)  Introduction to Objects

An Object in C++

class Student {/* State */char *name;char *address;float gpa;char *major;/* Behavior */

public:void print() {

cout << "Name = " << name;// print other attributes here }

};

Student s ;s is an object of type Student

Page 8: (a very brief)  Introduction to Objects

What is a Class?

A number of people or things grouped together because of likenesses; kind; sort ...[Webster's 87]

A description of a set of objects with similar characteristics, attributes, and behaviors. [LaLonde & Pugh 90]

An abstract description of the data and behavior of a collection of similar objects [Budd 91]

Page 9: (a very brief)  Introduction to Objects

What is a Class? (cont'd) Templates (i.e., blueprint) for objects

Object Factory

Person Class

Telephone Class

Page 10: (a very brief)  Introduction to Objects

Messages and Methods

Person object

JohnMale40 getAge()

40

Methods are not stored with objects!

int getAge() { return age;}

a method

a message

Page 11: (a very brief)  Introduction to Objects

OO: The Defining Characteristics

Polymorphism Inheritance Encapsulation

Easy to remember, just think of

P I E

Page 12: (a very brief)  Introduction to Objects

Inheritance A object/class can extend the capability of a

previously defined object/class (Thine classes or types shalt inherit from their ancestors)

Organization: Generalization/Specialization hierarchy

Person

Student

Page 13: (a very brief)  Introduction to Objects

Encapsulation An object should hide things from other objects,

limiting visibility about what "I know and do." [Object International]

(Thou shalt encapsulate thine objects)

Data

Methods

Page 14: (a very brief)  Introduction to Objects

Polymorphism

means many forms The interpretation of a message is in the hands of the

receiver; i.e., the same message can be interpreted differently by different receivers (Thou shalt not bind prematurely)

Name: BillySex: MaleSalary: 5K

Name: Mary Sex: FemaleHoursWorked: 40 Rate: $100

annualSalary?$60,000/yr

annualSalary?$208,000/yr

SalariedEmployee HourlyEmployee

Page 15: (a very brief)  Introduction to Objects

Polymorphism: Example

Problem:Want to print a variety of objects from a given container

ContainerSquare1

Square2Circle1

Circle2

Star1

Page 16: (a very brief)  Introduction to Objects

Polymorphism: Example (2)

Traditional Solution: // static, inflexible

p := first object;while (not end of container) {

switch (p->tag) {case (square): printSquare (p);case (circle): printCircle (p);case (star): printStar (p);default: error();

}next p;

}

Page 17: (a very brief)  Introduction to Objects

Polymorphism: Example (3)

Object-Oriented Solution: // dynamic, flexible

p := first object;while (not end of container) {

p.print(); next p;

}

Page 18: (a very brief)  Introduction to Objects

Traditional– based on top-down, functional decomposition

"What routines/functions are needed to solve the problem?"

Object-Oriented– based on bottom-up, object decomposition;

the idea of objects that interact with each other

"What are the fundamental objects in the system? what do they look like? How do they interact with each other? What

associated routines do they need?"

Traditional vs. OO Software Development

Page 19: (a very brief)  Introduction to Objects

Traditional

Object-Oriented

Traditional vs. OO Software Development (2)

Function1 Function2 FunctionN

data structure data structure

Obj1 Obj2 ObjN

MessageMessage