This project demonstrates the concept of polymorphism in C# using a company structure, where various roles (CEO, Auditor, Department Director, etc.) are represented as classes inheriting from a common base and implementing shared interfaces.
The project includes:
- Interfaces:
IBaseEmployee
,IClient
,ICompanyStaff
, andIPerson
. - Base Classes:
Employee
,Manager
, andClient
. - Derived Classes:
CEO
,Auditor
,DepartmentDirector
. - Company Class: Manages the company’s staff and clients, allowing for operations like adding new members and displaying their information.
- Polymorphism: Classes like
CEO
,Auditor
, andDepartmentDirector
inherit fromManager
orEmployee
and implement abstract methods in their own way. - Interfaces: Interfaces such as
IClient
,ICompanyStaff
, andIBaseEmployee
enforce a contract for shared methods and properties across different classes. - Abstraction: Abstract classes such as
Employee
andManager
provide a base for common behaviors while requiring derived classes to provide specific implementations. - Encapsulation: Class properties like
Position
,Salary
, andDepartment
are encapsulated with getters and setters, ensuring controlled access.
IPerson
: A base interface for all people-related entities.IClient
: ExtendsIPerson
and includes client-specific properties likeEmail
andTelephoneNumber
.IBaseEmployee
: Provides the basic structure for employee roles, including properties likePosition
andSalary
, and a methodReceiveSalary()
.ICompanyStaff
: CombinesIPerson
andIBaseEmployee
, and adds theDisplayInformation()
method for staff members.
Employee
: An abstract class defining common properties for all employees, such asId
,Name
,Position
,Salary
, and methods likeReceiveSalary()
,Work()
, andDisplayInformation()
.Manager
: An abstract class inheriting fromEmployee
and adding manager-specific methods likeControlTheProcess()
.
Client
: ImplementsIClient
, representing a company's client.Auditor
: ExtendsEmployee
to represent a specific type of employee responsible for auditing.CEO
: Inherits fromManager
, representing the highest role in the company.DepartmentDirector
: Inherits fromManager
and represents a director responsible for a department in the company.
using Company;
Company company = new Company();
// Creating staff
CEO ceo = new CEO { Id = 1, Name = "John Doe", Gender = "Male" };
Auditor auditor = new Auditor { Id = 2, Name = "Jane Smith", Gender = "Female" };
DepartmentDirector director = new DepartmentDirector { Id = 3, Name = "Alex Brown", Gender = "Non-binary" };
// Adding staff to the company
company.AddNewMemberToTheStaff(ceo);
company.AddNewMemberToTheStaff(auditor);
company.AddNewMemberToTheStaff(director);
// Displaying staff information
company.DisplayCompanyStafInformation();
*************************COMPANY STAFF*********************
*****MANAGER********
Position: CEO
Name: John Doe
Salary: 8000
********************
******EMPLOYEE********
Name: Jane Smith
Salary: 3000
Position: Auditor
**********************
*****MANAGER********
Position: Departament Director
Name: Alex Brown
Salary: 5000
Departament: Financial
********************
***********************************************************
- Clone this repository to your local machine.
- Open the solution in Visual Studio or your preferred C# development environment.
- Run the project to see the polymorphism in action.
- Staff Management: Easily add and manage different types of employees and clients.
- Flexible Hierarchy: Use polymorphism to extend the company structure and create new roles as needed.
- Console Output: Display information about staff members dynamically through the DisplayCompanyStafInformation() method.