Skip to content

jpsduarte/SchoolSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

🏫 School System — OOP in C#

A didactic project demonstrating the four pillars of Object-Oriented Programming in C#.

📁 Project Structure

SchoolSystem/
├── Interfaces/
│   ├── IEvaluable.cs      → Contract: CalculateAverage() and GetGrade()
│   └── IReport.cs         → Contract: GenerateReport()
├── Models/
│   ├── Person.cs          → ABSTRACT class (base for Student and Teacher)
│   ├── Student.cs         → Inherits Person, implements IEvaluable and IReport
│   └── Teacher.cs         → Inherits Person, implements IReport
├── Services/
│   └── Classroom.cs       → Groups Students and Teacher, implements IReport
├── Program.cs             → Entry point — demonstrates all concepts
└── SchoolSystem.csproj

🧠 Concepts Demonstrated

1. 🔒 Encapsulation

  • Private fields (_name, _ssn, _grades) exposed only through controlled properties
  • Setters with validation (e.g. SSN with 9 digits, grades between 0 and 10)
  • Internal logic protected (enrollment ID generation, salary calculation by experience)
// Grades can only be added via method — which validates the value
student.AddGrade(8.5);  // ✅ OK
student.AddGrade(15);   // ❌ Throws exception

2. 🧬 Inheritance

  • Student and Teacher both inherit from Person (abstract class)
  • Constructors use base(...) to reuse the parent class logic
  • protected modifier allows controlled access in subclasses
public class Student : Person { ... }
public class Teacher : Person { ... }

3. 🎭 Polymorphism

  • Introduce() is virtual in Person and overridden in Student and Teacher
  • GetType() is abstract: forces each subclass to provide its own implementation
  • A List<Person> can hold Students and Teachers — the correct method is called at runtime
List<Person> people = new() { teacher, student1, student2 };
foreach (var p in people)
    Console.WriteLine(p.Introduce()); // Each one responds differently!

4. 🔌 Interfaces & Abstractions

  • IEvaluable → implemented only by Student (has grades and an average)
  • IReport → implemented by Student, Teacher, and Classroom
  • Allows different objects to be treated uniformly via the interface type
List<IReport> reports = new() { teacher, student, classroom };
foreach (var r in reports)
    Console.WriteLine(r.GenerateReport()); // Each generates its own

▶️ How to Run

cd SchoolSystem
dotnet run

Requirement: .NET 8 SDK

About

School System describing OOP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages