1_OOPconcepts (1)
1_OOPconcepts (1)
Concepts
19CSE201-Advanced Programming
What is object oriented
programming?
Object-oriented programming (OOP) is a
programming language model in which programs
are organized around data, or objects, rather than
functions and logic.
Example1
Example2
Class
A class is a user defined blueprint or prototype
Class is a group of similar objects.
The definitions of the states and behaviors of an object are
organized into a class.
class Thus, a class is the generic definition
for a set of similar objects.
One or more objects described by the class are instantiated
at runtime.
The objects are called instances of the class.
Class (Contd..)
Abstraction
An abstraction is an act of representing essential features
without including background details.
Data Abstraction may also be defined as the process of
identifying only the required characteristics of an object and
ignoring the irrelevant details.
What is encapsulation ?
Binding code and data together into a single unit .
Other way to think about encapsulation is, it is a protective
shield that prevents the data from being accessed by the
code outside this shield.
Data and code is hidden from other classes.
Inheritance
Inheritance is an OOPS concept in which one object
acquires the properties and behaviours of the parent object.
It’s creating a parent-child relationship between two
classes
Polymorphism
Polymorphism refers to the ability of a variable, object or
function to take on multiple forms.
OOP Vs. POP
Activity
Objects in Real World
1. You’ve been hired by your school to create a program that keeps track of
“students at your school and the courses they are taking”. Name 2 classes
that you would create in your program. Name 2 attributes (data kept in
instance variables) for each class.
2. Think about what data you need to keep track of for students and courses and
what methods you need. Note that the instance variables in the Person class
could also work for a Student class!
3.
Say you wanted to make a computer game from a board game that you are
playing. Think about what objects are in the game.
For example, here is the description for Monopoly (trademark Hasbro games):
“Buy, sell, dream and scheme your way to riches. Players buy, sell and trade to
win. Build houses and hotels on your properties and bankrupt your opponents to
win it all. Chance and Community Chest cards can change everything.”
What classes would you need to create a computer version of this game?
(Remember to look for the nouns). Take one of the classes you listed, and try to
come up with 2 pieces of data in that class that will be the instance variables