OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of...

33
OBJECT ORIENTED PROGRAMMING
  • date post

    20-Dec-2015
  • Category

    Documents

  • view

    218
  • download

    0

Transcript of OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of...

Page 1: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

OBJECT ORIENTED PROGRAMMING

Page 2: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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!

Page 3: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 4: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

POINTS OF DISCUSSION

• Object• Message• Event• Class• Property• Inheritance• Data Abstraction and

Encapsulation

Page 5: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 6: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 7: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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

Page 8: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 9: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

PROPERTY AND EVENTS

• An event is a signal for the object to perform its function

• Properties are defined characteristics of the object

Page 10: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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

Page 11: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 12: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 13: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 14: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 15: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

DATA ABSTRACTION

• Loosely defined category of objects that can be manipulated and used in a variety of different programs.

Page 16: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

DATA ENCAPSUALTION

Providing access to an object only through its messages, while keeping the details private

Page 17: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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”;

Page 18: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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 –

Page 19: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

A SIMPLE EXAMPLE

a:=List fromString: ‘Mary Jones’.

b:=List fromString: ‘Suzy Smith’.

C:=a+b.

Output:

‘Mary Jones, Suzy Smith’

Page 20: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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’

Page 21: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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

Page 22: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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

Page 23: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 24: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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!

Page 25: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 26: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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

Page 27: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 28: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 29: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 30: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 31: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 32: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.

Page 33: OBJECT ORIENTED PROGRAMMING What is Object Oriented Software? Software based on the creation of objects An object is a “black box” which receives and.

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.