Java中的数据类有哪些设计模式?

时间:2017-10-27 16:00:44

标签: java oop design-patterns

我有一个Java复杂的类,它主要负责存储数据。我想知道是否有任何设计模式可用于指导此类用例。 更具体地说,该课程是记录每学期学生整体表现的东西。

Class StudentReport{
    cgpa = 3.1;
    Set <SubjectReport> perSubjectReportSet;
    overallFeedback = "..."
    ...
}

Class SubjectReport{
   subjectName = "Subject_A";
   gpa = 2.4;

   // Test Details
   test = Pass;
   testQuestionAnsweredCount = 8;
   testQuestionsCount = 10;
   testFeedback = None; // Feedback if FAIL

   // Assignment Details
   assignment = Pass;
   ...

   //Exam Details
   finalExam = Fail;
   examQuestionAnsweredCount = 5;
   examCorrectlyAnsweredQuestionCount = 2;
   examQuestionsCount = 10;
   examFeedback = "Blah Blah OOP" // Feedback if FAIL
}

2 个答案:

答案 0 :(得分:0)

用于封装类属性的设计模式是私有类数据模式。它试图降低类属性的可见性

答案 1 :(得分:0)

描述:“我在Java中有一个复杂的类,它主要负责存储数据”有点笼统,不是每个对象都存储数据与行为相结合吗?

您的示例代码确实显示了设计:the composition pattern