330 likes | 378 Views
OBJECT ORIENTED PROGRAMMING. What is Object Oriented Software?. Software based on the creation of objects An object is a “black box” which receives and sends messages A black box contains code and data, which are merged into a single indivisible object As a user - Do not peek into the box!.
E N D
What is Object Oriented Software? • Software based on the creation of objects • An object is a “black box” which receives and sends messages • A black box contains code and data, which are merged into a single indivisible object • As a user - Do not peek into the box!
Why is it so famous? • Offers a new and powerful model for writing computer software • Improves maintenance, reusability and modifiability • Improves principles of modularity and information hiding.
POINTS OF DISCUSSION • Object • Message • Event • Class • Property • Inheritance • Data Abstraction and Encapsulation
INTRODUCTION • “Object Oriented Programming models real-world objects with software counterparts”, H.M.Deitel & P.J.Deitel • It is a type of programming where a programmer defines both data types and functions of a data structure.
What is an Object? • OOP encapsulates data and functions into packages called objects, that are intimately tied together. • Objects are individual instances of a class.
So, what is a class? • It determines everything about an object. • Spot is an object created from class Dog. • A method is simply the action that a message carries out. • The Dog class defines messages that the Dog objects can understand, like “bark” and “fetch”.
Message • Messages define the interface to the object • All communication to the object is done via the messages • Objects do not ordinarily perform their behavior spontaneously, rather a specific behavior is invoked when a message is sent.
PROPERTY AND EVENTS • An event is a signal for the object to perform its function • Properties are defined characteristics of the object
PROPERTIES • Take advantage of class relationships, where objects of a certain class have the same characteristics • Provide a more natural and intuitive way of viewing the program’s progress • Encapsulate data and functions into objects
INHERITANCE Inheritance is a form of software reusability in which new classes are created from existing classes by the absorption of attributes and behaviors, embellishing these with capabilities the new class requires.
INHERITANCE • In any good Object Oriented language, the programmer creates a subclass of the original class. This new class inherits all the existing messages, and therefore, all the behavior of the original class. • The original class is called the parent class or Super class, of the new class. • A subclass is said to be a specialization of its super class, and conversely, a super class a generalization of its subclass.
INHERITANCE • Promotes reuse • Programmers don’t start from the scratch when they write a new program. They reuse an existing repertoire of classes that have behaviors similar to what is required in the new program. • For example, after creating the class Dog, you might create a subclass called Wolf, which defines some wolf specific messages such as hunt.
INHERITANCE • It is more sensible to define a common class called Canine, of which both Dog and Wolf are sub classes • Much of the art of OOP is determining the best way to divide a program into an economical set of classes. • In addition to speeding development time, proper class construction and reuse results in far fewer lines of code, which translates to less bugs, and lower maintenance costs.
DATA ABSTRACTION • Loosely defined category of objects that can be manipulated and used in a variety of different programs.
DATA ENCAPSUALTION Providing access to an object only through its messages, while keeping the details private
A SIMPLE EXAMPLE Suppose, you wanted a data type called list(list of names) Struct list{ <definition of list structure here> }; List a, b, c; a = “Mary Jones”; b = “Suzy Smith”;
A SIMPLE EXAMPLE In C, adding the integers a and b produces an error; the language doesn’t know what to do with a and b because they are not numeric entities. They are strings –
A SIMPLE EXAMPLE a:=List fromString: ‘Mary Jones’. b:=List fromString: ‘Suzy Smith’. C:=a+b. Output: ‘Mary Jones, Suzy Smith’
A SIMPLE EXAMPLE The first two lines of code simply create List objects a and b from the two strings. This now works, because the list class was created with a method which specifically “knows” how to handle the message “+”. Hence, C will have the new value of a combination of the argument with its own object by striking them together with a comma separating them. ‘Mary Jones, Suzy Smith’
OBJECT ORIENTED LANGUAGES • There are almost two dozen of them today! • The leading commercial OOL’s are: • C++ • Smalltalk • Java • C++ is an OO version of C • Smalltalk is significantly faster to develop than C++ • Java is the latest, flashiest OO language
C++ - OBJECT ORIENTED LANGUAGE C++ is compatible with C (superset of C), so that existing code can be incorporated into C++ programs. C++ programs are fast and efficient, qualities which helped make C an extremely popular programming language. It sacrifices certain flexibility in order to remain efficient
C++ - OBJECT ORIENTED LANGUAGE • C++ uses compile-time binding, which means the programmer must specify the specific class of an object, which makes for high run-time efficiency and small code size, but it trades off some of the power to reuse the classes. • C++ has become so popular that most new compilers are C/C++ compilers.
C++ - OBJECT ORIENTED LANGUAGE • However, in order to take full advantage of OOP, one must program in C++, not C. • This often can be a major problem for C programmers. • Many programmers think they are coding in C++, but instead are only using a small part of the language’s object oriented power!
Smalltalk - OBJECT ORIENTED LANGUAGE • C++ makes some practical compromises to ensure fast execution and small code size, Smalltalk makes none. • It uses run-time binding, which means that nothing about the type of an object need be known before a Smalltalk program is run. • Smalltalk has a rich class library that can be easily reused via inheritance.
Smalltalk - OBJECT ORIENTED LANGUAGE • It also has a dynamic development environment • Smalltalk is not explicitly compiled, like C++ • It is syntactically very simple, much more so than either C or C++.
Java - OBJECT ORIENTED LANGUAGE • Java is designed as a portable language that can run on any web-enabled computer via that computer’s web browser. As such, it offers great promise as the standard internet and intranet programming language. • Java is a mixture of C++ and Smalltalk! • It has no pointers, low-level programming constructs that make error-prone programs.
Java - OBJECT ORIENTED LANGUAGE • Like Smalltalk, Java has garbage collection, a feature that frees the programmer from explicitly allocating and de-allocating memory. • It runs on a Smalltalk-style virtual machine, software built into web browser which executes the same standard compiled Java byte codes irrespective of the computer used.
Powerbuilder - OBJECT ORIENTED LANGUAGE • PowerBuilder is an object oriented application tool that allows to build powerful, multitier applications to run on multiple platforms and to interact with various databases. • Each menu or window you create is an object. • Each object contains properties, events and functions.
SUMMARY • An object is a bundle of variables and related methods • A method is an operation which can modify an object’s behavior. • A Class is a blueprint of an object. • When defining a Class, you must consider any possible sub class.
CONCLUSION Major advantages of OOP are • It can address the problems that increasing size and complexity cause • Produce more complete and understandable specifications and designs by using all major types of data abstraction • This approach speeds up the development of new programs, improves maintenance and reusability.
CONCLUSION However, OOP requires a major shift in thinking by programmers. The C++ offers an easier transition via C, but it still requires an OO design approach. Java promises much for web-enabling OO programs. Smalltalk offers a pure OO environment.
BIBLIOGRAPHY • C++ How to Program - Deitel & Deitel • Object Oriented Analysis - David Brown • Object Oriented Analysis and Design with applications - Grady Booch • What is Object-Oriented Software? An article by Terry Montlick • Design, Implementation and Management - Peter Rob Carlos Coronel.