0% found this document useful (0 votes)
4 views6 pages

Design Lab 123

The document covers the fundamentals of Object Oriented Programming (OOP) and its significance in software development, emphasizing concepts like classes, inheritance, strong typing, and polymorphism. It introduces the Unified Modeling Language (UML) for visualizing software systems and provides a practical example of implementing the Strategy Pattern through various shape classes. The content is structured into practical exercises aimed at enhancing understanding of OOP principles and design patterns.

Uploaded by

Rishi Cyberman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Design Lab 123

The document covers the fundamentals of Object Oriented Programming (OOP) and its significance in software development, emphasizing concepts like classes, inheritance, strong typing, and polymorphism. It introduces the Unified Modeling Language (UML) for visualizing software systems and provides a practical example of implementing the Strategy Pattern through various shape classes. The content is structured into practical exercises aimed at enhancing understanding of OOP principles and design patterns.

Uploaded by

Rishi Cyberman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Ananya Bansal 11242124

Practical 1
Aim: Course introduction. Review of the software development context in
relation to Object Oriented development. Working with classes.
Introduction
Software development is the process of designing, creating, testing, and maintaining
software applications. As software systems grow larger and more complex, it becomes
difficult to manage them using traditional programming approaches. Object Oriented
Programming (OOP) provides a structured way to develop software by modeling real-
world entities as objects.
OOP helps in organizing code, improving reusability, reducing complexity, and
making software easier to maintain. It is widely used in modern software development
languages such as Java, C++, and Python.
Software Development Context in Relation to OOP
In software development, problems are analyzed and broken down into smaller
components. Object Oriented Programming approaches this by identifying objects
from the real world and representing them in software.
Each object contains:
 Data (Attributes): Variables that store information about the object
 Behaviour (Methods): Functions that define what the object can do
By using OOP concepts, developers can build modular, flexible, and scalable software
systems.

Working with Classes


A class is a blueprint or template used to create objects. It defines the properties and
behaviours that the objects created from it will have.
Example of a Class in Java
class Student {
int age;
String name;
void study() {
[Link]("Student is studying");
Ananya Bansal 11242124

}
}

Creating an Object of a Class


Student s1 = new Student();
[Link] = "Ananya";
[Link] = 20;
[Link]();
In the above example, Student is a class and s1 is an object created from that class.

Object Oriented Programming plays an important role in software development by


providing a clear structure to programs. Classes and objects help represent real-world
entities in code, making programs easier to understand, manage, and maintain.
Ananya Bansal 11242124

Practical 2
Aim: The uses of inheritance in software design. Principles of strong typing and
substitution. Polymorphism with abstract classes and interfaces. Introduction to
UML.
Uses of Inheritance in Software Design
Inheritance is an important concept in object oriented software design that allows a
new class to derive properties and methods from an existing class. The existing class
is known as the superclass, while the derived class is called the subclass. Inheritance
represents an “is-a” relationship between classes.
The main use of inheritance is code reusability. Common attributes and methods can
be defined in a parent class and reused by multiple child classes, which reduces
duplication of code. This makes programs easier to maintain, as changes made in the
parent class are automatically reflected in child classes.
Inheritance also improves software extensibility. New features can be added by
creating new subclasses without modifying existing code. This supports scalable
software design and follows good programming practices. Additionally, inheritance
helps organize classes into a logical hierarchy, making large systems easier to
understand and manage.
Principles of Strong Typing and Substitution
Strong typing is a programming principle where every variable, object, and expression
has a clearly defined data type. The compiler strictly enforces type rules and does not
allow operations between incompatible types. This helps detect errors at compile time,
increases program safety, and improves code clarity. Languages such as Java strongly
enforce typing rules.
The principle of substitution states that an object of a subclass should be substitutable
for an object of its superclass without altering the correctness of the program. This
principle ensures that inheritance is used properly and that subclass behavior remains
consistent with the expectations defined by the parent class. Following this principle
results in reliable and predictable object oriented designs.
Polymorphism with Abstract Classes and Interfaces
Polymorphism is the ability of an object to take many forms. It allows a single method
or interface to represent different underlying implementations depending on the object
type at runtime. Polymorphism increases flexibility and reduces dependency between
classes.
Ananya Bansal 11242124

An abstract class is a class that cannot be instantiated and may contain both abstract
methods and concrete methods. Abstract methods do not have a body and must be
implemented by subclasses. Abstract classes are used when multiple related classes
share common behavior but require different implementations of certain methods.
An interface defines a set of methods that a class must implement. It provides
complete abstraction and supports multiple inheritance by allowing a class to
implement more than one interface. Interfaces are used to define standard behavior
that can be shared across unrelated classes.
Both abstract classes and interfaces enable runtime polymorphism and help achieve
loose coupling and better software design.
Introduction to UML
Unified Modeling Language (UML) is a standardized modeling language used to
visualize, specify, and document object oriented systems. UML helps developers plan
the structure and behavior of a system before coding begins.
UML provides various types of diagrams to represent different aspects of a system.
 Class diagrams show the structure of classes and their relationships.
 Object diagrams represent instances of classes at a particular time.
 Use case diagrams describe system functionality from a user’s perspective.
 Sequence diagrams illustrate interactions between objects over time.
Using UML improves communication among developers and stakeholders and helps
in understanding, designing, and maintaining complex software systems.

Practical 3
Ananya Bansal 11242124

Aim: Write program to understand The Strategy Pattern.


Class Diagram:

Code:
interface Shape {
double getArea(); }
class Circle implements Shape {
private double rad;
public Circle(double rad) {
[Link] = rad; }
@Override
public double getArea() {
return 3.14 * rad * rad; } }
class Rectangle implements Shape {
private double length;
private double width;
public Rectangle(double length, double width) {
[Link] = length;
[Link] = width;}
@Override
public double getArea() {
return length * width; }}
class Triangle implements Shape {
private double base;
private double height;
Ananya Bansal 11242124

public Triangle(double base, double height) {


[Link] = base;
[Link] = height; }
@Override
public double getArea() {
return 0.5 * base * height; } }
class Area {
private Shape shape;
public Area(Shape shape) {
[Link] = shape; }
public double calcArea() {
return [Link](); }}
public class Prog {
public static void main(String[] args) {
Area circle = new Area(new Circle(7));
[Link]("Area of Circle: " + [Link]());
Area rectangle = new Area(new Rectangle(8,10));
[Link]("Area of Rectangle: " + [Link]());
Area triangle = new Area(new Triangle(6, 12));
[Link]("Area of Triangle: " + [Link]());
}
}

Output:

You might also like