(a very brief) introduction to objects
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 PresentationTRANSCRIPT
(a very brief) Introduction to Objects
by Dr. Billy B. L. Lim
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.
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)
An "Object" in C
/* This is a struct in C */
struct Student { char* ssn; char* name; float gpa; char* major; };
struct Student s1, s2;
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
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
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]
What is a Class? (cont'd) Templates (i.e., blueprint) for objects
Object Factory
Person Class
Telephone Class
Messages and Methods
Person object
JohnMale40 getAge()
40
Methods are not stored with objects!
int getAge() { return age;}
a method
a message
OO: The Defining Characteristics
Polymorphism Inheritance Encapsulation
Easy to remember, just think of
P I E
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
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
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
Polymorphism: Example
Problem:Want to print a variety of objects from a given container
ContainerSquare1
Square2Circle1
Circle2
Star1
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;
}
Polymorphism: Example (3)
Object-Oriented Solution: // dynamic, flexible
p := first object;while (not end of container) {
p.print(); next p;
}
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
Traditional
Object-Oriented
Traditional vs. OO Software Development (2)
Function1 Function2 FunctionN
data structure data structure
Obj1 Obj2 ObjN
MessageMessage