0% found this document useful (0 votes)
19 views16 pages

Mcs 219

The document covers the principles of Object-Oriented Programming (OOP), including encapsulation, abstraction, inheritance, and polymorphism, along with basic constructs like classes and objects. It also discusses system design, including tasks such as architectural, interface, data, and component design, and explains concepts like aggregation, composition, and the role of abstract classes. Additionally, it includes diagrams for an Online Learning System, state diagrams for an Online Shopping System, and mappings of object classes to database tables.

Uploaded by

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

Mcs 219

The document covers the principles of Object-Oriented Programming (OOP), including encapsulation, abstraction, inheritance, and polymorphism, along with basic constructs like classes and objects. It also discusses system design, including tasks such as architectural, interface, data, and component design, and explains concepts like aggregation, composition, and the role of abstract classes. Additionally, it includes diagrams for an Online Learning System, state diagrams for an Online Shopping System, and mappings of object classes to database tables.

Uploaded by

mylon.rainer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Course Code : MCS-219

Course Title : Object Oriented Analysis and Design

Q1: Explain basic philosophy of object orientation. Explain basic constructs of object
orientation with example.

Ans :- *Object-Oriented Programming (OOP) Philosophy:

Object-Oriented Programming (OOP) is a programming paradigm based on the


concept of "objects," which are instances of classes. OOP focuses on organizing
software design around data, or objects, rather than functions and logic. The main
principles of OOP are:

1. Encapsulation: Bundling data (attributes) and methods (functions) that operate on


the data within a single unit (class) and restricting access to some of the object's
components.

2. Abstraction: Hiding complex implementation details and showing only the essential
features of an object.

3. Inheritance: Creating new classes from existing ones to promote code reuse and
establish a hierarchical relationship.

4. Polymorphism: Allowing objects to be treated as instances of their parent class,


enabling one interface to be used for different data types.

Basic Constructs of Object Orientation

• Class: A blueprint for creating objects.


• Object: An instance of a class.
• Attributes: Variables within a class that hold data.
• Methods: Functions defined within a class that describe the behaviors of the
objects.
• Constructor: A special method to initialize objects.
• Inheritance: Mechanism for a class to inherit attributes and methods from
another class.
• Polymorphism: Ability to use a single interface for different underlying forms
(data types).

Example in Python

python

class Animal:

def __init__(self, name):

self.name = name

def make_sound(self):

print(f"{self.name} makes a sound")

class Dog(Animal): # Inherits from Animal

def make_sound(self): # Method Overriding

print(f"{self.name} barks")

# Creating objects

generic_animal = Animal("Some Animal")

dog = Dog("Buddy")

# Accessing methods

generic_animal.make_sound() # Output: Some Animal makes a sound

dog.make_sound()

# Output: Buddy barks


This example demonstrates OOP principles: Animal is a class with a method
make_sound(), Dog is a subclass inheriting from Animal, and Dog overrides the
make_sound() method to provide specific behavior.

Q2: Draw class diagram for Online Learning System. Make necessary assumptions.

Ans :- Sure, here is a basic class diagram for an Online Learning System:

```

+--------------------------------+

| Online Learning |

+--------------------------------+

| - courses: Course[] |

| - users: User[] |

+--------------------------------+

| + addCourse(course: Course) |

| + removeCourse(course: Course) |

| + addUser(user: User) |

| + removeUser(user: User) |

+--------------------------------+

+-------------------------+ | +------------------------+

| Course | | | User |

+-------------------------+ | +------------------------+

|- courseId : int | ------|- userId : int

|- courseName : string | *---|- username : string

|- instructor : string | |- email : string


|- studentsEnrolled : int | |- password : string

+- contentModules: Module[] +- ----|-- enrolledCourses: Course[]

+- assignmentsDueDate: Date +- ----|

+- quizzesDueDate: Date +

+- videosAvailable: boolean +

- enrollStudent(studentId:int): void

- addModule(moduleName:string): void

- removeModule(moduleName:string): void

```

Q3: Explain briefly object modeling , dynamic modeling and functional modeling with
the help of suitable diagrams.

Ans :- Object modeling, dynamic modeling, and functional modeling are all essential
aspects of software development. Here's a brief explanation of each with
suitable diagrams:

1. Object Modeling:

Object modeling is the process of representing real-world entities as software


objects. It helps in identifying the key concepts, attributes, and behaviors of the
system. Class diagrams are commonly used in object-oriented design to illustrate the
relationships and structures of objects within a system.

2. Dynamic Modeling:

Dynamic modeling focuses on depicting the behavior and interactions between


objects over time. It helps in understanding how objects collaborate to achieve
specific functionalities or respond to external events. Sequence diagrams are often
used to depict these interactions, showing the sequence of messages exchanged
between objects during a particular scenario.

3. Functional Modeling:

Functional modeling involves representing how a system functions from a user's


perspective, focusing on its inputs, processes, and outputs. Use case diagrams are
commonly employed for functional modeling as they showcase different user
interactions (actors) with the system through various use cases or functionalities.

Below are examples demonstrating each type of diagram:

- Object Modeling (Class Diagram):

```

+--------------------------------+

| Student |

+--------------------------------+

| - studentId : int |

| - name : string |

| - email : string |

+--------------------------------+

+------------------------+

| Course |

+------------------------+

|- courseId : int |

|- courseName : string |

|- instructor : string |

+- contentModules: Module[]|

+- assignmentsDueDate: Date|

+- quizzesDueDate: Date |

- enrollStudent(studentId:int): void

- addModule(moduleName:string): void
- removeModule(moduleName:string): void

```

- Dynamic Modeling (Sequence Diagram):

```

Actor System

| /\

| ||

|---> Request ----||

||<-- Response ---||

\/

```

- Functional Modeling (Use Case Diagram):

```

[User]

[Login]--[ViewCourses]--[EnrollCourse]

```

Q4: Draw state diagram for Online Shopping System. Also, list the assumptions made.

Ans :- State Diagram for Online Shopping System:

```
+----------------+ +---------------+

| Logged Out | Login | Logged In |

+----------------+ +---------------+

/\ /\

|| ||

|| Logout || Logout

\/ \/

+----------------+ +---------------+

| View Products | Select | View Cart |

+----------------+-------------+---------------+

/\ Add to Cart /\

|| ||

|| Remove from Cart ||

\/ \/

No Items in Cart Checkout

```

Assumptions:

1. The system assumes that users have valid login credentials to access the online
shopping platform.

2. It assumes that products are available for viewing and purchasing.

3. The system assumes that users can add items to their cart, remove items from their
cart, and proceed to checkout.

4. It is assumed that the payment process is not included in this state diagram.

5. The state diagram does not include details about user registration or account
management.
These assumptions are made for simplifying the state diagram and focusing on the
core states and transitions within the online shopping system.

Q5: What is aggregation? How is it related to composition? Explain role of abstract


class in system design with the help of example.

Ans :- Aggregation is a type of association that represents a "has-a"


relationship between two classes, where one class has a reference to another. It can
be thought of as a weaker form of association. Composition, on the other hand, is a
stronger form of aggregation in which the child object's existence is dependent
on the parent object.

The role of an abstract class in system design is to serve as a blueprint for other
classes and cannot be instantiated itself. An abstract class may contain abstract
methods that must be implemented by its subclasses and define common behaviors
and attributes that multiple subclasses will share.

For example:

Consider an online music streaming system design. We can have an abstract class
called MediaItem which represents all types of media items available for streaming
such as songs, albums, podcasts etc.

```java

abstract class MediaItem {

String title;

int duration;

public MediaItem(String title, int duration) {

this.title = title;

this.duration = duration;

}
public void play() {

// Play the media item

public abstract void displayInfo();

class Song extends MediaItem {

String artist;

public Song(String title,int duration,String artist){

super(title,duration);

this.artist=artist ;

@Override

public void displayInfo() {

System.out.println("Title: " +title+ ", Duration: " +duration+


", Artist:"+artist);

```

In this example, MediaItem acts as an abstract base class for different types of media
items within the system design. The Song subclass extends from the MediaItem
abstract class and provides specific implementations while inheriting common
attributes/methods defined in the abstract base class (MediaItem). This approach
allows for reusability and consistency among different types of media items in the
system design.

Q6: What is system design? What are the major tasks performed during system
design? Explain.

Ans :- System design is the process of defining and developing a detailed blueprint for
a system, including its architecture, components, modules, interfaces, and data for a
specific purpose or end goal. It involves translating the requirements gathered during
the system analysis phase into a tangible plan that can be used to build and
implement the system.

The major tasks performed during system design include:

1. Architectural Design: This involves defining the overall structure of the system,
including its components and their relationships, as well as determining how different
parts of the system will interact with each other.

2. Interface Design: This task focuses on designing how users will interact with the
system through its user interface. It includes creating wireframes and mockups to
visualize how users will navigate through the system.

3. Data Design: This task involves designing the data model for the system, including
defining data structures, databases, storage mechanisms, and data flow within and
outside of the system.

4. Component Design: This entails breaking down the overall architecture into smaller
components or modules that can be developed independently. The design also
specifies how these components will communicate with each other.

5. Security Design: This involves identifying potential security threats to the system
and designing measures to protect it from unauthorized access or breaches in
security.

6. Testing Strategy Design: Developing a plan for testing various aspects of the
designed systems such as functionality testing, integration testing etc.,
Overall, these tasks are aimed at creating a comprehensive plan that serves as a
roadmap for implementing an effective and efficient computer-based solution that
meets business requirements while also being reliable, scalable and secure.

Q7: Map the object classes created in Question 2 above into database tables. Make
necessary assumptions.

Ans :- Certainly! Based on the object classes created in Question 2, here is a


hypothetical mapping to database tables:

1. Object Class: Product

- Attributes: productID (primary key), productName, description, price,


quantityInStock

Database Table:

```

CREATE TABLE Product (

productID INT PRIMARY KEY,

productName VARCHAR(255),

description TEXT,

price DECIMAL(10,2),

quantityInStock INT

);

```

2. Object Class: Customer

- Attributes: customerID (primary key), firstName, lastName, email, phone

Database Table:
```

CREATE TABLE Customer (

customerID INT PRIMARY KEY,

firstName VARCHAR(100),

lastName VARCHAR(100),

email VARCHAR(255),

phone VARCHAR(15)

);

```

3. Object Class: Order

- Attributes: orderID (primary key), customerID (foreign key referencing Customer


table), orderDate

Database Table:

```

CREATE TABLE Order (

orderID INT PRIMARY KEY,

customerID INT,

orderDate DATE,

FOREIGN KEY (customerID) REFERENCES Customer(customerID)

);

```

4. Object Class: OrderItem


- Attributes: itemID (primary key), orderID (foreign key referencing Order table),
productID(foreign key referencing Product table), quantity

Database Table:

```sql

CREATE TABLE OrderItem (

item_id INT PRIMARY KEY,

order_id INT ,

product_id INT ,

quantity_ordered int ,

FOREIGN KEY(order_id) REFERENCES orders(orderid) ON DELETE CASCADE ON


UPDATE CASCADE ,

FOREIGN KEY(product_ID ) REFERENCES products(productid )

);

```

This mapping assumes that each object class corresponds to a separate table in the
database and that appropriate data types and relationships are established based on
their attributes.

The actual database design may vary based on specific requirements and additional
assumptions about constraints and relationships between the objects.

Q8: Write short notes on following (minimum in 250 words):

i) Mapping designs to code

ii) Design Optimization


i) Mapping designs to code
Mapping designs to code is an essential process in software development that
involves translating the architectural and detailed design of a system into actual
programming code. This step is crucial as it bridges the gap between the conceptual
design of a system and its practical implementation through coding.

When mapping designs to code, several key steps are involved:

1. Understanding Design Specifications: The first step is to thoroughly understand the


design specifications, including the architectural design, database design, interface
design, and component-level design. This involves reviewing documents such as
architectural blueprints, data models, interface mockups, and detailed component
designs.

2. Selecting Programming Language: Based on the requirements and nature of the


project, developers need to select a suitable programming language or technology
stack that aligns with the system's design specifications. For instance, if a
system requires high performance or real-time processing capabilities, a language
like C++ or Java may be chosen.

3. Translating Design Elements into Code: Developers then begin translating various
elements of the system's design into actual code components. This includes
writing classes and methods based on object-oriented designs; creating database
schemas and queries based on data models; implementing user interfaces based on
UI/UX wireframes; and developing algorithms and logic based on detailed component
designs.

4. Applying Best Coding Practices: During this process, developers need to adhere to
best coding practices such as writing clean code with proper naming conventions;
following coding standards for readability; incorporating error handling mechanisms;
optimizing performance where necessary; ensuring security measures are applied
throughout coding procedures.

5.Testing & Refinement : After mapping ,testing should be carried out so any
errors can be caught & fixed early in process .This ensures that final product will
meet customer requirements
6.Documentation : Proper documentation should be maintained through out this
stage

Overall ,mapping designs to code is an intricate process that requires attention to


detail ,error free implementation & following best coding practices . It turns
theoretical concepts into functional reality by converting visual representations from
architecture diagrams wireframes etc into tangible systems which users can interact
with .

ii) Design Optimization


Design optimization refers to the process of refining and improving the design of a
product, system, or process to enhance its performance, efficiency, and
effectiveness. This iterative process involves analyzing various design parameters
and making adjustments to achieve the best possible outcome. Here are some key
aspects of design optimization:

1. Performance Improvement: Design optimization aims to enhance performance


metrics such as speed, accuracy, reliability, and functionality. This may involve
refining components or systems to operate more efficiently or meet specific
performance requirements.

2. Cost Reduction: Optimizing designs often involves finding ways to reduce


production costs without compromising quality or functionality. This may include
using alternative materials, streamlining manufacturing processes,making
components more durable,and minimizing waste.

3. Resource Efficiency: Design optimization also focuses on maximizing resource


utilization by minimizing energy consumption,reducing material usage,and increasing
overall sustainability.These efforts can leadto environmental benefitsand cost
savingsin the long run.

4. Simulation and Modeling: The use of simulation tools and computer-aided


modeling is essential in design optimization.This allows engineersand designers
toeasily test various scenarios,optimize parameters,and predict howchangeswill
impactperformance before actual implementation.This helpsin identifyingthe optimal
solutionwithout extensive prototypingor experimentation.
5.Reliabilityand Robustness: Optimization seeks to improve product reliabilityby
identifyingweakpointsin a systemor component'sdesignand reinforcing themto
enhancetheir robustnessand longevity.Thisis particularlyimportantfor safety-critical
systemswhere failure could have catastrophic consequences.

6.Multi-disciplinary Approach:Theoptimaldesignof complexsystems often


requiresexpertisefrom multiple disciplines,such as engineering,digital
modeling,machine learning,and materials science.By integrating knowledgefrom
different fields,the overall designcan be improvedtomeet diverse
requirementsandspecifications

In summary,the goalof designoptimizationisto createproductsandsystemsthat


deliversuperiorperformancewhile minimizingcostsand resources.This
iterativeprocess requiresa combinationof creativity,critical thinking,and
solidengineeringprinciples.It is an essentialstep in ensuringthatdesignsare notonly
aesthetically pleasingbut thoroughly engineeredfor
superiorfunctionalityandreliability.

You might also like