1stand2nd Class UNIT 1 OOP.pptx
1stand2nd Class UNIT 1 OOP.pptx
► Text Books
► Stanley B Lippman, Josee Lajoie, Barbara E, Moo, “C++ primer”, Fifth edition, Addison-Wesley,
2012
► Bjarne Stroustrup, The C++ programming Language, Addison Wesley, 4th edition, 2013
► Harvey M. Deitel and Paul J. Deitel, C++ How to Program, 7th edition, Prentice Hall, 2010
► Maureen Sprankle and Jim Hubbard, Problem solving and Programming concepts, 9th
edition,Pearson Eduction, 2014
Outline
► Introduction to OOP
► Programming Languages
► Evolution : Low level languages (Machine programming using 0’s and 1’s)
Middle level language (Assembly programming using “mnemonics”)
High level language (Procedure-Oriented or Structured Programming Languages
and Object – Oriented Programming Languages using general
English words with set of grammar rules)
► Are all functional…!
Introduction to OOP
► Programming Languages
► Evolution : Low level languages (Machine programming using 0’s and 1’s)
Middle level language (Assembly programming using “mnemonics”)
High level language (Procedure-Oriented or Structured Programming Languages
and Object – Oriented Programming Languages using general
English words with set of grammar rules)
► Are all functional…!
“YES”
► Class
► A class is the representation of an idea, a concept, in the code
► Classes significantly helps maintenance by allowing us to avoid making mistakes and finding
bugs easily if mistake happens
► In a nutshell,
► Classes are essentially user defined data types. Classes are where we create a layout for the structure of
methods and attributes
► Individual objects are instantiated, or created from this blueprint.
► Classes contain fields for attributes, and methods for behaviors
Introduction to OOP
► Objects
► Objects are the basic run-time entities in an OO system, means problems are decomposed into
number of entities called objects and then builds data and functions around these objects
Solving the problem is mainly done by focusing on entities rather than the functions to be performed by the
entities
► Objects can be a person, a place, a bank account, a table of data etc.
► Objects are instances of classes containing data and code to manipulate the data.
► Data means variables (properties) and code means methods (functions).
► In a simple term, objects are the variable of type Class.
► As they are variable, they take space in memory and have an associated address
Introduction to OOP
► Examples
Introduction to OOP
► Examples
Introduction to OOP
► Objects
► In our examples, Rufus is an instance of the Dog class, Fluffy & Maisel are the instances of Herding
Dog class, Ford and Toyota are the instances of Car class
Introduction to OOP
► In programming context
Introduction to OOP
► Data encapsulation is a mechanism of bundling the data and the functions that use them OR grouping of data
and functions into a single unit called class.
► The data is not accessible to the outside world (other functions of the program).
► Only those functions which are wrapped in the class can access it.
► Functions provide an interface between the objects data and the program
► This insulation of data from direct access by the program is called data hiding or information hiding
► Data abstraction is a mechanism of exposing only the interfaces and hiding the implementation details from
the user.
OR
It refers to the act of representing essential features without including the background details or explanation.
Introduction to OOP
► Inheritance
► Inheritance supports reusability, it allows classes to inherit features of other classes.
► Class whose properties gets inherited is called Parent class and the class which inherits the properties of other
class is called Child Class
► Put another way, parent classes extend attributes and behaviors to child classes.
► If basic attributes and behaviors are defined in a parent class, child classes can be created extending the
functionality of the parent class, and adding additional attributes and behaviors.
► For example, herding dogs have the unique ability to herd animals. In other words, all herding dogs are dogs, but
not all dogs are herding dogs. We represent this difference by creating a child class Herding Dog from the parent
class Dog, and then add the uninique herd() behavior.
► The benefits of inheritance are programs can create a generic parent class, and then create more specific child
classes as needed. This simplifies overall programming, because instead of recreating the structure of
the Dog class multiple times, child classes automatically gain access to functionalities within their parent
class.
Introduction to OOP
► Polymorphism
► Polymorphism is extensively used in implementing inheritance
► In Greek term, Polymorphism means the ability to take more than one form.
► Operator Overloading
► An operation may exhibit different behaviors in different instances. The operation depends on the type of data
used in the operation.
► For eg. : “+” for integers is addition of two numbers [2 + 3 = 5]
for strings is concatenation of two strings [Ram + Eats = RamEats]
► Function Overloading
► Similarly, using a single function name to perform different types of tasks within a class with different
function parameters, like Draw() function name can be defined differently for circle, square, rectangle with
the same name Draw().
Introduction to OOP
► Polymorphism
► Function Overriding
► Using a single function name to perform
different types of tasks in Parent and child
classes with same function parameters.
Introduction to OOP
► The UML definition was led by Grady Booch, Ivar Jacobson, and Jim Rumbaugh
► UML simplifies the process of software design, making a "blueprint" for construction
► In Essence: a tool used through the analysis and design phases of system development
for expressing the constructs and relationships of complex systems
UML Class Diagram
Class representation
• Describe the structure of the system in terms of classes and objects
• Primary purpose during analysis workflow: to create a vocabulary that is used by both
the analyst and users
attributes
operations
UML Class Diagram
/ age : Date
Classes Attributes (Cont’d)
Person
name : String
address : Address
birthdate : Date
ssn : Id
eat
sleep Operations describe the class behavior
work and appear in the third compartment.
play
Classes Operations cont’d
PhoneBook
You can specify an operation by stating its signature: listing the name,
type, and default value of all parameters, and, in the case of functions, a
return type.
Relationships
• associations
•Aggregate
•Composite
Inheritance Relationship
Person
Employee Customer
Manager Engineer
Inheritance Relationship Employee
hireDate
receivePay
performWork
Manager Engineer
department certifications
bonus
hireEmployee analyze
promoteEmployee design
Inheritance
Generalization:
Person Employee
UML permits a class to inherit
from multiple superclasses,
although some programming
languages (e.g., Java) do not
permit multiple inheritance.
Teacher
Association Relationships
If two classes in a model need to communicate with each other, there must
be link between them.
A simple association is the relationship which describes the way they are
related to each other
Association Relationships cont’d
Student Instructor
1..*
Association Relationships cont’d
The example indicates that every Instructor has one or more Students:
Student Instructor
1..*
Association Relationships cont’d
membership
Student Team
1..* 1..*
eats
Birds Insects
0..* 0..*
Association Relationships cont’d
member of
1..* 1..*
Student Team
1 president of 1..*
Association Relationships cont’d
Engine
Car
Transmission
Association Relationships cont’d
Scrollbar
1 1
Window Titlebar
1 1
Menu
1 1 .. *
Basic of C++