Low cohesion的說明
High cohesion的說明
假設有個學生類別, 目前它有很多的函式:
public class Student
{
public string Name { get; set; }
public int StudentId { get; set; }
public Department Department { get; set; }
public Student(string name, int studentId, Department department)
{
Name = name;
StudentId = studentId;
Department = department;
}
public void CalculateTuitionFee()
{
// Tuition fee calculation logic
}
public void GenerateTranscript()
{
// Transcript generation logic
}
public void SaveToDatabase()
{
// Database save logic
}
public void SendEmail()
{
// Email sending logic
}
}
public class Student
{
public string Name { get; set; }
public int StudentId { get; set; }
public Department Department { get; set; }
public Student(string name, int studentId, Department department)
{
Name = name;
StudentId = studentId;
Department = department;
}
public void CalculateTuitionFee()
{
// Tuition fee calculation logic
}
public void GenerateTranscript()
{
// Transcript generation logic
}
public void SaveToDatabase()
{
// Database save logic
}
public void SendEmail()
{
// Email sending logic
}
}
public class TuitionFeeCalculator
{
public decimal CalculateTuitionFee(Department department)
{
// Tuition fee calculation logic
// ...
}
}
public class TranscriptGenerator
{
public void GenerateTranscript(Student student)
{
// Transcript generation logic
// ...
}
}
public class DatabaseService
{
public void SaveStudentToDatabase(Student student)
{
// Database save logic
// ...
}
}
public class EmailService
{
public void SendEmail(string recipient, string sender, string message)
{
// Email sending logic
// ...
}
}