Skip to content
VUBuddy

CS304 Midterm Notes

Object Oriented Programming PDF 601 KBUpdated 23 Oct 2026
Midterm past paper CS304 Midterm Notes PDF 601 KB
vubuddy.com
Type
Midterm past paper
Course
CS304 Object Oriented Programming
Size
PDF 601 KB
Updated
23 Oct 2026
Free download 0 of 3 used today
Download free · 601 KB

You get 3 free files a day on the website. Add the Chrome extension for 30 a day.

Unlimited downloads in the Android app Get it free on Google Play

Preview text

Text from pages 1, 2, 3 of 24. Download the file for all 24 pages.

Object Oriented Programming CS304

What is Object-Orientation?

It is a technique in which we visualize our programming problems in the form of objects and their interactions as happens in real life. Object orientation makes it easier for us to solve our real world problems by thinking solution of the problem in terms of real world objects. So we can say that in our daily life everything can be taken as an object that behaves in a certain way and has certain attributes.

What is a Model?

A model is an abstraction of something real or conceptual. We need models to understand an aspect of reality.

Model Examples

Highway maps - Architectural models - Mechanical models In the context of programming models are used to understand the problem before starting developing it.

Object-Orientation - Advantages

As Object Oriented Models map directly to reality We can easily develop an object oriented model for a problem. Everyone can easily understand an object oriented model. We can easily implement an object oriented model for a problem using any object oriented language like c++ using its features1 like classes, inheritance, virtual functions and so on…

What is an Object?

An object is,

  1. Something tangible (Ali, School, House, Car).
  2. Something conceptual (that can be apprehended

intellectually for example time, date and so on…). An object has, 1. State (attributes) 2. Well-defined behavior (operations) 3. Unique identity

Information Hiding:

Information hiding is one of the most important principles of OOP inspired from real life which says that all information should not be accessible to all persons. Private information should only be accessible to its owner. By Information Hiding we mean “Showing only those details to the outside world which are necessary for the outside world and hiding all other details from the outside world.” In the perspective of Object Oriented Programming Information Hiding is, “Hiding the object details (state and behavior) from the users” Information Hiding is achieved in Object Oriented Programming using the following principles,

  • All information related to an object is stored within the object
  • It is hidden from the outside world
  • It can only be manipulated by the object itself

We can achieve information hiding using Encapsulation and Abstraction, so we see these two concepts in detail now,

Encapsulation

Encapsulation means “we have enclosed all the characteristics of an object in the object itself” Encapsulation and information hiding are much related concepts (information hiding is achieved using Encapsulation)

Advantages of Encapsulation

Simplicity and clarity

As all data and functions are stored in the objects so there is no data or function around in program that is not part of any object and is this way it becomes very easy to understand the purpose of each data member and function in an object.

Low complexity

As data members and functions are hidden in objects and each object has a specific behavior so there is less complexity in code there will be no such situations that a functions is using some other function and that functions is using some other function.

Better understanding

Everyone will be able to understand whole scenario by simple looking into object diagrams without any issue as each object has specific role and specific relation with other objects.

Interface:

Interface is a set of functions of an object that he wants to expose to other objects.

It is actual implementation of the behavior of the object in any Object Oriented language.

Messages

Objects communicate through messages they send messages (stimuli) by invoking appropriate operations on the target object. The number and kind of messages that can be sent to an object depends upon its interface

Abstraction

Real life objects have a lot of attributes and many kinds of behaviors but most of the time we are interested in only that part of the objects that is related to the problem. this concept is called “Abstraction”. Abstraction is a way to cope with complexity and it is used to simplify things.

Principle of abstraction:

“Capture only those details about an object that are relevant to current perspective”

Abstraction has following major advantages,

  1. It helps us understanding and solving a problem using object oriented approach as it hides extra irrelevant details of objects.
  2. Focusing on single perspective of an object provides us freedom to change implementation for other aspects of for an object later.

Inheritance

A child inherits characteristics of its parents, besides inherited characteristics, a child may have its own unique characteristics

Inheritance in Classes

If a class B inherits from class A then it contains all the characteristics (information structure and behaviour) of class A The parent class is called base class and the child class is called derived class Besides inherited characteristics, derived class may have its own unique characteristics

Inheritance – “IS A” or “IS A KIND OF” Relationship

Inheritance – Advantages

  1. Reuse
  2. Less redundancy 3. Increased maintainability

Reuse with Inheritance

Main purpose of inheritance is reuse; we can easily add new classes by inheriting from existing classes. Select an existing class closer to the desired functionality, create a new class and inherit it from the selected class, add to and/or modify the inherited functionality

Generalization

In OO models, some classes may have common characteristics. We extract these features into a new class and inherit original classes from this new class. Base class encapsulates the idea of commonality of derived classes. Base class is general class representing common behavior of all derived classes. This concept is known as Generalization.

Sub-typing & Specialization

We want to add a new class to an existing model We have developed an existing class hierarchy Find an existing class that already implements some of the desired state and behavior Inherit the new class from this class and add unique behavior to the new class

Sub-typing (Extension)

Sub-typing means that derived class is behaviourally compatible with the base class Derived class has all the characteristics of base class plus some extra characteristics Subtyping and generalization are related concepts, Subtyping (extension) and generalization is a way to look same thing in two ways. Sub typing is looking at things from Top to bottom whereas in generalization we look at things from bottom to top.

Specialization (Restriction)

We want to add a class to existing hierarchy of classes having many similarities to already existing classes but some part of its behaviour is different or restricted. In that case we will use the concept of specialization. Specialization means that derived class is behaviourally incompatible with the base class Behaviourally incompatibility means that base class can’t always be replaced by the derived class Derived class has some different of restricted characteristics than of base class. Add method behaviour is present in both base and derived classes but derived class behaviour is different in derived class. Derived class will not exhibit the behaviour of base class but it is overriding behaviour of base class with its own behaviour.

Overriding

A class may need to override the default behaviour provided by its base class Derived class overrides the behaviour of its base class. Reasons for overriding Provide behaviour specific to a derived class (specialization) Extend the default behaviour (extension) Restrict the default behaviour (restriction) Improve performance It is used for the implementation of inheritance.

Abstract Classes

In our examples we made classes for shape and person. These are abstract concepts and the classes we make against abstract concepts are called abstract classes. They are present at or near the top in the class hierarchy to present most generalized behaviour. An abstract class implements an abstract concept Main purpose is to be inherited by other classes Can’t be instantiated Promotes reuse Abstract Classes cannot exist standalone in an object model

Concrete Classes

The entities that actually we see in our real world are called concrete objects and classes made against these objects are called concrete classes. A concrete class implements a concrete concept These are used to instantiate objects in our programs Provides implementation details specific to the domain context A concrete class may exist in an object model independently Concrete classes mostly lie below the top of class hierarchy in a good object model.

Multiple Inheritance

Sometimes we want to reuse characteristics of more than one parent class, in that case we need to inherit a class from more than one classes.

Advantage of Multiple Inheritance:

As was the case with simple (single) inheritance multiple inheritance also decreases redundant code as we can inherit a class from many classes and can use their functions without the need to write them again. However, there are more disadvantages of multiple inheritance, than its advantages.

Problems with Multiple Inheritance

Increased complexity

Amphibious vehicle hierarchy is a complicated as this class is derived from two classes that will make code more complex and less understandable however this is obvious as amphibious vehicle is a complicated vehicle. It is generic problem.

Reduced understanding

Due to increased complexity of class hierarchy the object model becomes difficult it understand especially for someone who is looking it first time.

Duplicate features

As we are deriving a single class from more than one class so there is a chance of duplication of features (same methods in both parents), following problems may arise due to duplicate features,

Solution to Diamond Problem

Some languages disallow diamond hierarchy others provide mechanism to ignore characteristics from one side. There are two Cases while solving diamond problem virtual inheritance and non-virtual inheritance

Association:

Interaction of different objects in OO model (or in problem domain) is known as association. In object oriented model, objects interact with each other in order to perform some useful work, while modeling these objects (entities) is done using the association. Usually an object provides services to several other objects. An object keeps association with other objects to delegate tasks. This association can be represented with a line along an arrow head ( ) or without arrow head.

Kinds of Association:

There are two main types of association which are then further subdivided i.e

  1. Class Association 2. Object Association

1. Class Association

Class association is implemented in terms of Inheritance. Inheritance implements generalization/specialization relationship between objects. Inheritance is considered class association.

  • In case of public inheritance it is “IS-A” relationship.
  • In case of private inheritance it is “Implemented in terms of” relationship.

2. Object Association

It is the interaction of standalone objects of one class with other objects of anther class. It can be of one of the following types,

  • Simple Association

Simple Association

The two interacting objects have no intrinsic relationship with another object. It is the weakest link between objects. It is a reference by which one object can interact with some other object. Simple association can be categorized in two ways,

  • With respect to direction (navigation) • With respect to number of objects (cardinality)

Kinds of Simple Association w.r.t Navigation

a. One-way Association b. Two-way Association

a. One-way Association

In One-way association we can navigate along a single direction only, it is denoted by an arrow towards the server object.

b. Two-way Association

In two-way association we can navigate in both directions, it is denoted by a line between the associated objects

Kinds of Simple Association w.r.t Cardinality

a. Binary Association b. Ternary Association c. N-ary Association

a. Binary Association

It associates objects of exactly two classes; it is denoted by a line, or an arrow between the associated objects.

All CS304 files →
CS304 Object Oriented Programming All CS304 handouts, past papers, quizzes and MCQs in one place. Open course page

Get more out of VUBuddy, for free

Android app Free on Google Play
  • Unlimited downloads
  • The explanation behind every MCQ answer
  • Study offline on slow data
Get the Android app
Chrome extension Free on the Chrome Web Store
  • 30 downloads a day instead of 3
  • Sign in and buy Pro Semester here
Add to Chrome

One Pro Semester membership works in both the extension and the app.