System Design 📄
Below is a simple OOP design + Java implementation for a School Management System that supports:
- Managing Students
- Managing Teachers
- Searching them
- Publishing results
- Notifying teachers via Email
- Notifying parents via SMS
This example intentionally demonstrates several OOP relationships:
| Relationship | Example in Design |
|---|---|
| Inheritance | Person → Student, Person → Teacher |
| Composition | Student → Result |
| Aggregation | School → Students/Teachers |
| Association | Teacher ↔ Student |
| Dependency | ResultService → NotificationService |
| Can-Do | Notifier interface (EmailNotifier, SMSNotifier) |
Core Classes​
Person
├── Student
└── Teacher
School
├── List<Student>
└── List<Teacher>
Result
ResultService
Notifier (interface)
├── EmailNotifier
└── SMSNotifier
Flow​
Admin publishes result
↓
ResultService
↓
Save result to Student
↓
Notify Teacher (Email)
Notify Parent (SMS)
Java Implementation​
Person (Base Class – Inheritance)​
abstract class Person {
protected int id;
protected String name;
public Person(int id, String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
}
Student (Inheritance + Composition)​
Student has a Result
class Student extends Person {
private String parentPhone;
private Result result;
public Student(int id, String name, String parentPhone) {
super(id, name);
this.parentPhone = parentPhone;
}
public void setResult(Result result) {
this.result = result;
}
public Result getResult() {
return result;
}
public String getParentPhone() {
return parentPhone;
}
}
Teacher Class​
class Teacher extends Person {
private String email;
public Teacher(int id, String name, String email) {
super(id, name);
this.email = email;
}
public String getEmail() {
return email;
}
}
Result Class (Composition)​
class Result {
private int marks;
private String grade;
public Result(int marks, String grade) {
this.marks = marks;
this.grade = grade;
}
public int getMarks() {
return marks;
}
public String getGrade() {
return grade;
}
}
Notifier Interface (Can-Do Relationship)​
interface Notifier {
void send(String message, String destination);
}
Email Notifier​
class EmailNotifier implements Notifier {
@Override
public void send(String message, String email) {
System.out.println("Sending EMAIL to " + email + ": " + message);
}
}
SMS Notifier​
class SMSNotifier implements Notifier {
@Override
public void send(String message, String phone) {
System.out.println("Sending SMS to " + phone + ": " + message);
}
}
School Class (Aggregation)​
School has students and teachers
import java.util.*;
class School {
private List<Student> students = new ArrayList<>();
private List<Teacher> teachers = new ArrayList<>();
public void addStudent(Student s) {
students.add(s);
}
public void addTeacher(Teacher t) {
teachers.add(t);
}
public Student findStudent(int id) {
for (Student s : students) {
if (s.getId() == id) return s;
}
return null;
}
public Teacher findTeacher(int id) {
for (Teacher t : teachers) {
if (t.getId() == id) return t;
}
return null;
}
}
Result Service (Dependency)​
Uses notification services.
class ResultService {
private Notifier emailNotifier;
private Notifier smsNotifier;
public ResultService(Notifier emailNotifier, Notifier smsNotifier) {
this.emailNotifier = emailNotifier;
this.smsNotifier = smsNotifier;
}
public void publishResult(Student student, Teacher teacher, Result result) {
student.setResult(result);
String message = "Result for " + student.getName()
+ ": Marks=" + result.getMarks()
+ ", Grade=" + result.getGrade();
emailNotifier.send(message, teacher.getEmail());
smsNotifier.send(message, student.getParentPhone());
}
}
Main Application​
public class SchoolApp {
public static void main(String[] args) {
School school = new School();
Student s1 = new Student(1, "Alice", "0170000000");
Teacher t1 = new Teacher(1, "Mr. Rahman", "rahman@school.com");
school.addStudent(s1);
school.addTeacher(t1);
Notifier email = new EmailNotifier();
Notifier sms = new SMSNotifier();
ResultService resultService = new ResultService(email, sms);
Result result = new Result(85, "A");
resultService.publishResult(s1, t1, result);
}
}
Example Output​
Sending EMAIL to rahman@school.com: Result for Alice: Marks=85, Grade=A
Sending SMS to 0170000000: Result for Alice: Marks=85, Grade=A
OOP Relationships Used​
| Relationship | Example |
|---|---|
| Inheritance | Student extends Person, Teacher extends Person |
| Composition | Student → Result |
| Aggregation | School → Students, Teachers |
| Association | Student ↔ Teacher during result publishing |
| Dependency | ResultService → Notifier |
| Can-Do | Notifier interface |