---
title: "Interface vs implementation"
subject: "Object Oriented Analysis and Design"
chapter: 4
key: "semester_6/object_oriented_analysis_and_design:interface-vs-implementation"
source: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/interface-vs-implementation
site: BCT Engineering
---

# Interface vs implementation

Object Oriented Analysis and Design · Chapter 4: Implementation

- Asked in: 2072 Asoj, 5 marks; 2073 Bhadra, 6 marks (asked 2 times)
- Video: [Interfaces](https://www.youtube.com/watch?v=Epgdiw-qbH8) — Object Oriented Analysis and Design
- Answer checked by Claude Sonnet 5.5 on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/interface-vs-implementation
- Whole chapter: https://www.bctengineer.com/md/semester_6/object_oriented_analysis_and_design/chapter-4

## Question

Explain the concept of interface and implementation in object oriented design and implementation. (How interface differ from implementation? Explain the concept of interface and implementation in any object oriented programming languages.)

## Short answer

Interface defines what operations a class provides (signatures, contracts) without revealing how they work. Implementation is the hidden code and data that realize those operations. Separating them enables encapsulation and loose coupling: clients depend only on the stable interface, so implementations can change freely.

## Answer

#### Concept
- **Interface:** the *what*, the public face of a class or component. It declares the set of operations (names, parameters, return types and contract) that other objects can use. It says nothing about how they work. In UML it is a classifier with `<<interface>>`; in Java it is the `interface` construct.
- **Implementation:** the *how*, the actual code and data (private fields, algorithms) that carry out the operations. It is hidden from the clients.

Separating them is the basis of **encapsulation, abstraction and loose coupling**: clients depend only on the interface, so the implementation can be changed or replaced without changing the clients.

```text
   Client ----uses----> <<interface>>
                         Shape
                         + area()
                          ^     ^
                          :     :  (realization)
                      Circle   Rectangle
                      (implementations)
```

#### Difference

| Point | Interface | Implementation |
|---|---|---|
| Describes | What can be done | How it is done |
| Content | Operation signatures (and constants) | Code, attributes, algorithms |
| Visibility | Public | Mostly private/hidden |
| Instances | Cannot be created directly | Concrete classes create objects |
| Change | Should be stable | Can change freely |
| Multiplicity | A class can implement many interfaces, and one interface can have many implementations | Each implementation is one concrete class |

#### Example in Java

```java
interface Shape {                    // interface
    double area();
}
class Circle implements Shape {      // implementation 1
    private double r;
    Circle(double r) { this.r = r; }
    public double area() { return Math.PI * r * r; }
}
class Rectangle implements Shape {   // implementation 2
    private double w, h;
    Rectangle(double w, double h) { this.w = w; this.h = h; }
    public double area() { return w * h; }
}
// Client depends only on the interface
Shape s = new Circle(2);
System.out.println(s.area());
```

In C++ the same is done with an abstract class that has pure virtual functions (`virtual double area() = 0;`), and in C# with the `interface` keyword.

## Check yourself

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

1. How do interface and implementation differ?
   A. Interface is how, implementation is what
   B. Both describe the same thing
   C. Interface declares what can be done; implementation holds the code of how
   D. Interface holds the private data
   Answer: C. The interface declares operation signatures; the implementation contains the code and data. (Key point: What versus how)

2. What is the benefit of clients depending only on the interface?
   A. Implementation can change without changing clients
   B. Clients become larger
   C. Interfaces can be instantiated
   D. Implementations become public
   Answer: A. This gives encapsulation and loose coupling, so implementations can be replaced freely. (Key point: Benefit of separation)

3. How is an interface expressed in C++?
   A. With the interface keyword
   B. With an abstract class having pure virtual functions
   C. With a private constructor
   D. It is not possible
   Answer: B. C++ uses abstract classes with pure virtual functions such as virtual double area() = 0; Java and C# use interface. (Key point: Interface in languages)

## Related in Object Oriented Analysis and Design

- [Algorithmic vs object-oriented decomposition](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aalgorithmic-vs-oo-decomposition) — Object Oriented Analysis and Design, chapter 1
- [Object oriented system and core concepts](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aoo-system-concepts-explained) — Object Oriented Analysis and Design, chapter 1
- [Structural model vs implementation model](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Astructural-vs-implementation-model) — Object Oriented Analysis and Design, chapter 1
- [Marina class diagram implementation code](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Amarina-class-diagram-implementation-code) — Object Oriented Analysis and Design, chapter 4
- [Conceptual, specification, implementation model classification](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Ahospital-conceptual-specification-implementation) — Object Oriented Analysis and Design, chapter 2
- [Short note: Distributed system implementation](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Ashort-note-distributed-implementation-issues) — Object Oriented Analysis and Design, chapter 4

## Related in other subjects

- [Compare procedural and object oriented programming](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aprocedural-vs-oop-compare) — Object Oriented Programming, chapter 1
- [File system layout; interface vs implementation](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Afs-layout-interface-vs-implementation) — Operating System, chapter 5
- [Generations of programming languages](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Agenerations-programming-languages) — Computer Programming, chapter 1, asked 4×
- [Categories of programming languages](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Acategorise-languages) — Computer Programming, chapter 1
