Lecture 8
Lecture 8
CS/CE 224/272
Nadia Nasir
• Static variables
• Function overloading
Object-oriented programming (or OOP)
Object-oriented programming (or OOP) is a paradigm or pattern of programming
whereby the solution to a programming problem is modelled as a collection of
collaborating objects.
An object is an entity that possesses both state (or properties or attributes) and
behaviour.
An example of an object is a car.
A car has attributes (e.g., colour, size, weight, fuel capacity, number of passengers, etc.).
A car has behaviour represented by its methods (e.g., start engine, turn left/right,
accelerate, stop, turn on wipers, etc.).
A class is a special kind of object that’s used as a template for creating instances of
itself. Think of it like a cookie cutter that produces cookies (or objects).
OOP Concepts
Encapsulation enables a class to hide the inner details of how it works from the outside
world.
With Encapsulation, a class can change the way it works internally and as long as those
internals are not visible to the rest of the system, those changes will have no effect on
how the class is interacted with.
Example: Keep the body of the car the same, but change the engine
Encapsulation
Instance variables are kept private and accessor methods are made public to achieve
this.
Inheritance