Introduction to OO Programming : Introduction to OO Programming D.S Giri
http://SliceData.BlogSpot.com
dharmendra.giri@gmail.com 1 LipNi Services
Object-Oriented Programming : An approach to application development
Appropriate for large-scale applications with teams of developers
OO programming paradigm: collection of objects Object-Oriented Programming 2 LipNi Services
Slide 3 : Global Variables -lifetime spans program execution.
Local Variables - lifetime limited to execution of a single routine.
Nested Scopes - allow functions to be local.
Static Variables - visible in single scope.
Modules - allow several subroutines to share a set of static variables.
Module Types - multiple instances of an abstraction.
Classes - families of related abstractions. The Evolution of OOPS 3 LipNi Services
Why OO-Programming? : Reduces conceptual load by reducing amount of detail
Provides fault containment
Can’t use components (e.g., a class) in inappropriate ways
Provides independence between components
Design/development can be done by more than one person Why OO-Programming? 4 LipNi Services
Slide 5 : An instance of a class is know as an Object.
Languages that are based on classes are know as Object-Oriented.
Eiffel
C++
Modula-3
Ada 95
Java
SmallTalk
Microsoft .NET Languages - C# and VC++ etc Keys to OO Programming 5 LipNi Services
Benefits of Object-Oriented Development : Promotes code reuse
Reduces code maintenance
Simplifies extending applications Benefits of Object-Oriented Development 6 LipNi Services
Methods : Functions still do the work in OO!
But now they…
…just know what they need to know!
…generally contain less code! 7
© Copyright 1997-2007 Methods LipNi Services
Slide 8 : Encapsulation (data hiding)
Enable programmer to group data & subroutines (methods) together, hiding irrelevant details from users
Inheritance
Enable a new abstraction (i.e., derived class) to be defined as an extension of an existing abstraction, retaining key characteristics
Dynamic method binding
Enable use of new abstraction (i.e., derived class) to exhibit new behavior in context of old abstraction Keys to OO Programming 8 LipNi Services
Slide 9 : Choosing a constructor
How are constructors supported in the language?
References and values
Value model ? object creation results from elaboration
Execution order of initialization
E.g., with derived classes
Garbage Collection?
Don’t need destructors! Initialization & Finalization of Objects 9 LipNi Services
Object-Oriented Programming : Object-Oriented Programming For power programmers and large-scale application development Parent Class Child Class Encapsulation Classes and objects Inheritance 10 LipNi Services
Classes and Objects : Objects are actors in your application
Refer to individual pieces of data
A class defines the data and behavior of objects
Objects in your application are instances of a class Classes and Objects 11 LipNi Services
Objects : An object is a thing
More precisely, an object is a representation of a thing
Has characteristics
We call these "attributes" or "properties"
Properties are just variables rebranded!
Those things which the thing has
Has behaviors
We call these "methods"
Methods are just functions rebranded!
Those things which the thing does 12
© Copyright 1997-2007 Objects LipNi Services
Inheritance : Defines subclasses
Creates “is a” relationship
Example: Camera phone “is a” cell phone
Reuse common functionality
Specialization
Extend or override common functionality for specific needs Inheritance 13 LipNi Services
Encapsulation : Treat each object as a black box
Well-defined interface of data and methods
Must use this interface in the application
All data is private
Methods can be public, private, or protected Encapsulation 14 LipNi Services
OO Design – Testing Cell Phones : Test cell phones and camera phones by the cell phone placing calls and the camera phone placing calls and taking pictures
Break the application into “nouns” and “action verbs”
Camera phones are types of cell phones that also contain a camera
Cell phones make calls
Camera phones make calls and take pictures
To test a cell phone, a call must be placed and verified
To test a camera phone, the cell phone and camera functionality must be tested
To test a camera, an image must be taken and compared to a reference
Nouns generally map to classes or objects
Verbs generally map to functions OO Design – Testing Cell Phones 15 LipNi Services
Slide 16 : An Example in C++ 16 LipNi Services
Thank You : Questions ? Thank You 17 LipNi Services