---
title: "Framework and design pattern with example"
subject: "Object Oriented Analysis and Design"
chapter: 3
key: "semester_6/object_oriented_analysis_and_design:framework-design-pattern-example"
source: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/framework-design-pattern-example
site: BCT Engineering
---

# Framework and design pattern with example

Object Oriented Analysis and Design · Chapter 3: Object Oriented Design

- Asked in: 2069 Poush, 6 marks
- Video: [Object Oriented Design Patterns Explained](https://www.youtube.com/watch?v=aiSAO2AXa9g) — A Dev' Story
- Answer checked by Claude Sonnet 5.5 on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/framework-design-pattern-example
- Whole chapter: https://www.bctengineer.com/md/semester_6/object_oriented_analysis_and_design/chapter-3

## Question

What is framework? How design pattern is useful? Explain any one design pattern in detail with suitable example.

## Short answer

A framework is a reusable semi-complete application skeleton providing architecture and common behavior, customized via inversion of control. Design patterns are named proven solutions to recurring design problems, offering reuse, common vocabulary, better quality, and faster design. The Singleton pattern ensures exactly one instance with global access via private constructor, static instance reference, and static getInstance() method, useful for loggers or database managers.

## Answer

#### Framework
A **framework** is a reusable, semi-complete skeleton of an application: a set of cooperating classes and interfaces that provides the architecture and common behaviour for a family of applications. Developers customise it by writing subclasses or plugging in their own code, and the framework calls that code (inversion of control: "Hollywood principle - don't call us, we'll call you"). Examples: Spring, Hibernate, Struts, .NET, Java Swing, Angular.

#### How design patterns are useful
A **design pattern** is a named, tested solution to a commonly occurring design problem in a given context. Usefulness:
- Reuse of proven design experience instead of reinventing solutions.
- A common vocabulary ("use a Singleton here") for the team.
- Better quality: flexible, loosely coupled, maintainable designs.
- Faster design and better documentation.

#### Singleton pattern in detail
**Problem:** exactly one instance of a class is needed, with a global access point (e.g. a database connection manager, logger, or configuration).
**Solution:** make the constructor private, keep a static reference to the single instance, and provide a static method `getInstance()`.

```text
 +--------------------------+
 |        Logger            |
 |--------------------------|
 | - instance : Logger      |  (static)
 | - Logger()               |
 |--------------------------|
 | + getInstance() : Logger |  (static)
 | + log(msg)               |
 +--------------------------+
```

```java
public class Logger {
    private static Logger instance;       // the one object
    private Logger() { }                  // no outside creation
    public static synchronized Logger getInstance() {
        if (instance == null) instance = new Logger();
        return instance;
    }
    public void log(String msg) { System.out.println(msg); }
}
// use: Logger.getInstance().log("started");
```

**Consequences:** controlled access to the sole instance, saves resources, global but managed access; drawbacks: hidden dependency, harder unit testing, needs care in multi-threading.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the 'Hollywood principle' in a framework?
   A. Your code calls the framework only once
   B. The framework calls your plugged-in code
   C. Frameworks have no reusable classes
   D. Classes call each other randomly
   Answer: B. Inversion of control: the framework calls the developer's code ('don't call us, we'll call you'). (Key point: Framework and inversion of control)

2. Which is a benefit of design patterns?
   A. They remove the need for design
   B. They guarantee faster execution
   C. They give a common vocabulary and reuse of proven solutions
   D. They replace testing
   Answer: C. Patterns provide reuse of tested designs and a shared vocabulary. (Key point: Usefulness of patterns)

3. Which combination implements Singleton?
   A. Private constructor, private static instance, public static getInstance()
   B. Public constructor and a static counter
   C. Abstract class with many subclasses
   D. Final class with no methods
   Answer: A. A private constructor prevents outside creation; getInstance() returns the single static instance. (Key point: Singleton implementation)

4. Which is a drawback of Singleton?
   A. It uses more memory
   B. It cannot be used for loggers
   C. It allows many instances
   D. Hidden dependency and harder unit testing
   Answer: D. Global access hides dependencies and makes testing and multithreading harder. (Key point: Singleton drawbacks)

## Related in Object Oriented Analysis and Design

- [Pattern vs framework; GRASP patterns](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Apattern-vs-framework-grasp) — Object Oriented Analysis and Design, chapter 3
- [Pattern based design and benefits](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Apattern-based-design-benefits) — Object Oriented Analysis and Design, chapter 3

## Related in other subjects

- [Reuse framework versus program generator](https://www.bctengineer.com/question.md?key=semester_5%2Fsoftware_engineering%3Aframework-vs-generator) — Software Engineering, chapter 5
- [K1 and K2 of LLF from load pattern](https://www.bctengineer.com/question.md?key=semester_8%2Ftransmission_and_distribution_system_design%3Allf-k1-k2-load-pattern) — Transmission and Distribution System Design, chapter 6, asked 2×
- [Peak load, load factor and energy from load pattern](https://www.bctengineer.com/question.md?key=semester_8%2Ftransmission_and_distribution_system_design%3Aconsumer-class-load-pattern-transformer) — Transmission and Distribution System Design, chapter 6, asked 2×
- [Peak demand of load center from load pattern](https://www.bctengineer.com/question.md?key=semester_8%2Ftransmission_and_distribution_system_design%3Apeak-demand-load-center-load-pattern) — Transmission and Distribution System Design, chapter 6, asked 2×
