1 / 19

(a very brief) Introduction to Objects

(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:

steve
Download Presentation

(a very brief) Introduction to Objects

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. # 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: • PowerBuilder, Enfin, ObjectView, etc. • ORDBMSs/OODBMSs: • Oracle 10g, DB2 Viper, SQL Server 2005, etc. • ObjectStore, Gemstone, Versant, Ontos, OpenODB, Trellis, O2, Orion, etc. • Class Libraries • MFC, OWL, Tools.h++, etc. Why Object-Orientation: Observation

  3. 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) What is an Object?

  4. An "Object" in C /* This is a struct in C */ struct Student { char* ssn; char* name; float gpa; char* major; }; struct Student s1, s2;

  5. 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() ; An Object in Java creates an object of type Student

  6. class Student { /* State */ char *name; char *address; float gpa; char *major; /* Behavior */ public: void print() { cout << "Name = " << name; // print other attributes here } }; Student s ; An Object in C++ s is an object of type Student

  7. 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]

  8. Templates (i.e., blueprint) for objects • Object Factory What is a Class? (cont'd) Telephone Class Person Class

  9. Person object a message Messages and Methods John Male 40 getAge() int getAge() { return age; } 40 a method Methods are not stored with objects!

  10. OO: The Defining Characteristics • Polymorphism • Inheritance • Encapsulation Easy to remember, just think of P I E

  11. Person Student • 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 Inheritance

  12. An object should hide things from other objects, limiting visibility about what "I know and do." [Object International](Thou shalt encapsulate thine objects) Encapsulation Methods Data

  13. Name: Billy Sex: Male Salary: 5K Name: Mary Sex: Female HoursWorked: 40 Rate: $100 annualSalary? annualSalary? $208,000/yr $60,000/yr • 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) Polymorphism SalariedEmployee HourlyEmployee

  14. Polymorphism: Example • Problem:Want to print a variety of objects from a given container Container Square1 Square2 Circle1 Star1 Circle2

  15. Traditional Solution: // static, inflexiblep := 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 (2)

  16. Polymorphism: Example (3) • Object-Oriented Solution: // dynamic, flexiblep := first object;while (not end of container) { p.print(); next p;}

  17. Traditional vs. OO Software Development • 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?"

  18. Traditional vs. OO Software Development (2) • Traditional • Object-Oriented data structure data structure Function1 FunctionN Function2 ObjN Obj2 Obj1 Message Message

More Related