An interface isolation exemplary design pattern principles

  As this example student achievement management program, student achievement management program typically includes insertion results, delete results, modify the results to calculate the total score, calculated average print performance information, query performance information and other functions, if all of these functions into a Interface obviously not reasonable, the correct way is they were put into three modules input module, a statistics module and a print module, which is shown in Figure class:

          

   Source as follows:

public class ISPtest
{
    public static void main(String[] args)
    {
        InputModule input =StuScoreList.getInputModule();
        CountModule count =StuScoreList.getCountModule();
        PrintModule print =StuScoreList.getPrintModule();
        input.insert();
        count.countTotalScore();
        print.printStuInfo();
        //print.delete();
    }
}
//输入模块接口
interface InputModule
{
    void insert();
    void delete();
    void modify();
}
//统计模块接口
interface CountModule
{
    void countTotalScore();
    void countAverage();
}
//打印模块接口
interface PrintModule
{
    void printStuInfo();
    void queryStuInfo();
}
//实现类
class StuScoreList implements InputModule,CountModule,PrintModule
{
    private StuScoreList(){}
    public static InputModule getInputModule()
    {
        return (InputModule)newStuScoreList (); 
    } 
    public  static CountModule getCountModule () 
    { 
        return (CountModule) new new StuScoreList (); 
    } 
    public  static PrintModule getPrintModule () 
    { 
        return (PrintModule) new new StuScoreList (); 
    } 
    public  void INSERT () 
    { 
        System.out.println ( "input module insert () method is called!" ); 
    } 
    public  void delete () 
    { 
        System.out.println ( "input module delete () method is called!" ); 
    } 
    public void Modify () 
    { 
        System.out.println ( "Modify input module () method is called!" ); 
    } 
    public  void countTotalScore () 
    { 
        System.out.println ( "countTotalScore statistics module () method is called!" ); 
    } 
    public  void countAverage () 
    { 
        System.out.println ( "countAverage statistics module () method is called!" ); 
    } 
    public  void printStuInfo () 
    { 
        System.out.println ( "print module printStuInfo () method is called "! ); 
    } 
    public  void queryStuInfo () 
    {
        System.out.println ( "print module queryStuInfo () method is called!" ); 
    } 
}

  Operating results of the program are as follows:

Enter insert module () method is called! 
CountTotalScore statistics module () method is called! 
Print printStuInfo module () method is called!

Guess you like

Origin www.cnblogs.com/jing99/p/12576787.html