12429_basics of oops

14
Copyright ©2005 Department of Computer & Information Science Object Oriented Concepts

Upload: khushbu-thakur

Post on 03-Jun-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

8/11/2019 12429_basics of Oops

http://slidepdf.com/reader/full/12429basics-of-oops 1/14

Copyright ©2005 Department of Computer & Information Science

Object Oriented Concepts

8/11/2019 12429_basics of Oops

http://slidepdf.com/reader/full/12429basics-of-oops 2/14

 

Copyright ©2005 Department of Computer & Information Science

Goals

• Understand objects, their attributesand their methods.

• Understand the pillars of object-oriented programming asencapsulation, inheritance &

polymorphism.

8/11/2019 12429_basics of Oops

http://slidepdf.com/reader/full/12429basics-of-oops 3/14

 

Copyright ©2005 Department of Computer & Information Science

OOP Concepts

• Objects

• Attributes

• Methods• Events

• Abstraction & Classes• Constructors

8/11/2019 12429_basics of Oops

http://slidepdf.com/reader/full/12429basics-of-oops 4/14

 

Copyright ©2005 Department of Computer & Information Science

What is an object?

• An object is a unique programmingentity that has attributes to describe

it (like adjectives in grammar) andmethods to retrieve/set attributevalues (like verbs in grammar).

8/11/2019 12429_basics of Oops

http://slidepdf.com/reader/full/12429basics-of-oops 5/14

 

Copyright ©2005 Department of Computer & Information Science

 Attributes

• Programmers store an object’s data inattributes, also called properties.

• Attributes provide us a way todescribe an object, similar toadjectives in grammar.

• We can read property values orchange properties, assigning values.

8/11/2019 12429_basics of Oops

http://slidepdf.com/reader/full/12429basics-of-oops 6/14

 

Copyright ©2005 Department of Computer & Information Science

Methods

• Whereas attributes describe anobject, methods allow us to access

object data. Methods are like verbs ingrammar.

• We can manipulate object data,

stored in attributes, using methods.

8/11/2019 12429_basics of Oops

http://slidepdf.com/reader/full/12429basics-of-oops 7/14

 

Copyright ©2005 Department of Computer & Information Science

Events

• Object-oriented programming isinherently tied to user interaction.

Programs record interaction in theform of events.

• Events are changes in an object’s

environment to which it can react.

8/11/2019 12429_basics of Oops

http://slidepdf.com/reader/full/12429basics-of-oops 8/14

 

Copyright ©2005 Department of Computer & Information Science

 Abstraction

• One of the chief advantages ofobject-oriented programming is the

idea that programmers can essentiallyfocus on the “big picture” and ignorespecific details regarding the inner-

workings of an object. This concept iscalled abstraction .

8/11/2019 12429_basics of Oops

http://slidepdf.com/reader/full/12429basics-of-oops 9/14

 

Copyright ©2005 Department of Computer & Information Science

Classes

• How do programmers get byimplementing abstraction? They use a

programming structure called a class .• A class presents a blueprint of an

object, its properties and its methods.

8/11/2019 12429_basics of Oops

http://slidepdf.com/reader/full/12429basics-of-oops 10/14

 

Copyright ©2005 Department of Computer & Information Science

Instantiation

• To create an object based on a class,we create an instance of that class.

This process is called instantiation.• In Java, JavaScript and other

languages, we use a special method

called a constructor method  to createan instance of an object.

8/11/2019 12429_basics of Oops

http://slidepdf.com/reader/full/12429basics-of-oops 11/14

 

Copyright ©2005 Department of Computer & Information Science

Encapsulation

• Abstraction in OOP is closely relatedto a concept called encapsulation .

• Data and the ways to get at that dataare wrapped in a single package, aclass. The only way to access such

data is through that package. Thisidea translates to information hiding.

8/11/2019 12429_basics of Oops

http://slidepdf.com/reader/full/12429basics-of-oops 12/14

 

Copyright ©2005 Department of Computer & Information Science

Inheritance

• Another of the main tenets of OOP isinheritance . Inheritance allows

programmers to create new classesfrom existing ones.

• A child class inherits its properties

and attributes from its parents, whichprogrammers can change.

8/11/2019 12429_basics of Oops

http://slidepdf.com/reader/full/12429basics-of-oops 13/14

 

Copyright ©2005 Department of Computer & Information Science

Polymorphism

• Polymorphism describes howprogrammers write methods to do

some general purpose function.• Different objects might perform

polymorphic methods differently.

8/11/2019 12429_basics of Oops

http://slidepdf.com/reader/full/12429basics-of-oops 14/14

 

Copyright ©2005 Department of Computer & Information Science

Summary

• Programming objects are comprisedof attributes and methods.

• Classes provide programmers withblueprints of objects.

• To create an object from a class, weuse constructor methods to create aclass instance.