Presentation is loading. Please wait.

Presentation is loading. Please wait.

SNPL1 Woochang Lim What (Variable) + How (Function) = Object Objects are the physical and conceptual things we find in the universe around us. Object-Oriented.

Similar presentations


Presentation on theme: "SNPL1 Woochang Lim What (Variable) + How (Function) = Object Objects are the physical and conceptual things we find in the universe around us. Object-Oriented."— Presentation transcript:

1 SNPL1 Woochang Lim What (Variable) + How (Function) = Object Objects are the physical and conceptual things we find in the universe around us. Object-Oriented Thinking An Introduction to Object-Oriented Programming

2 SNPL2 History - Simula (1960s): Idea of objects to simulate real-world entities - SmallTalk (1970s): Using software objects for developing applications - 1980s: Other object-oriented programming (OOP) languages – C++, Eiffel. Problems in the software development - Software is difficult to develop, modify, and maintain. - Most software are delivered late and over budget. - Programmers are still having to create software from the ground-up because of no code reuse. Solutions - Structured programming - Object-Oriented Programming (OOP) Differences between the structured programming and the OOP - Structured programming: Data and functions are separately. - OOP: The related data and functions are replaced together within one unit.

3 SNPL3 Objects – A Black Box Object: Like a “black box” - Data+Code - Data: Information which the instructions operates on - Code(function): Sequences of computer instructions - Non-OOP languages: Data and code(function) are separately. State and behavior of an object - State of an object: One of the possible conditions in which an object may exists e.g. Light bulb: on/off - Behavior of an object: Set of operations the object can perform on itself e.g. Printer: Print whatever it receives No need to look inside an object – Information hiding

4 SNPL4 Classes and Messages Class: A generic definition for a set of similar objects Class provides the specifications for the objects behaviors and attributes. Objects are instances of a class. Example of Class: Animal Attributes: Having four legs and a tail Behaviors: Sleeping and eating Objects: Cat, elephant, and horse Messages: Requests for the receiver objects to carry out the indicated method or behavior and return the result of that action to the sender objects Example of Message: A “person” object sends the “light bulb” object a message to turn on. The “light bulb” object has a behavior that will change its state from off to on. The “light bulb” object turns itself on and indicates to the “person” object that its new state is on.

5 SNPL5 Encapsulation and Inheritance Encapsulation: The process of hiding the details of an object The only access to manipulate the object data is through its interface. It protects an object’s internal state from other programs. Also, other programs are protected from changes in the object. Therefore, it reduces the ripple effect. Inheritance: A code reuse mechanism to build new objects out of old ones. Inheritance defines a relationship among classes where one class shares the structure and behavior on one or more classes. Example of Inheritance: The class “feline” inherits all the behavior and attributes of the class “animal.” And the class “feline” also has a meow behavior that was not in the class “animal.” It provides a more flexible and adaptable system and enables polymorphism. “Software is not written, it is re-written.”

6 SNPL6 Polymorphism Polymorphism: Having many forms It provides the ability to use a single message to invoke many different kinds of behavior. Example of Polymorphism: A class “shape” with a draw behavior The draw behavior will draw any instances of shape. Classes “triangle,” “rectangle,” and “circle” are inheritances of the “shape.” Within these inherited classes of “triangle,” “rectangle,” and “circle,” the draw behavior is rewritten to draw a triangle, rectangle, and circle, respectively. If a “triangle” object calls the draw behavior, a triangle will be drawn. For the “rectangle,” a rectangle will be drawn. And a circle is drawn for the “circle” object. Therefore, the individual implementation of each different shape is hidden behind a single interface or behavior, “draw.”

7 SNPL7 Object-Oriented Languages C++: An object-oriented version of C - It is compatible with C. C++ has all merits of the C languages. Easy to use for the C programmer - Compilation language: Fast execution and small code size Smalltalk: A pure object-oriented language. - It runs on the virtual machine. - It provides a rich class library. Java: Latest, flashiest object-oriented language - It is designed as a portable language that can run on any web-enabled computer via that computer’s Web browser. (The standard Internet and Intranet programming language) - Mixture of C++ and Smalltalk It has the syntax of C++, making it easy to learn. It runs on a Smalltalk-style virtual machine.


Download ppt "SNPL1 Woochang Lim What (Variable) + How (Function) = Object Objects are the physical and conceptual things we find in the universe around us. Object-Oriented."

Similar presentations


Ads by Google