1、好的设计和差的设计的区别: 功能强大,易用性强、可靠安全、可被利用
好的设计的原则:单一职责原则、开闭原则、里氏代换原则、依赖倒置原则、接口隔离原则、合成复用原则、迪米特法则
2、观察者模式代码
public interface Subject{ public void addObserver(Observer o); public void deleteObserver(Observer o); public void notifyObservers();}public interface Observer{ public void hearTelephone(String heardMess);}public class SeekJobCenter implements Subject{ String mess; boolean changed; ArrayList<Observer> personList; SeekJobCenter(){ personList=new ArrayList<Observer>(); mess=""; changed=false; } public void addObserver(Observer o){ if(!(personList.contains(o))) personList.add(o); } public void deleteObserver(Observer o){ if(personList.contains(o)) personList.remove(o); }public class UniverStudent implements Observer{ Subject subject; File myFile; UniverStudent(Subject subject,String fileName){ this.subject=subject; subject.addObserver(this); myFile=new File(fileName); } public void hearTelephone(String heardMess){ try{ RandomAccessFile out=new RandomAccessFile(myFile,"rw"); out.seek(out.length()); byte [] b=heardMess.getBytes(); out.write(b); System.out.print(" 我是一个大学生 ,"); System.out.println(" 我向文件 "+myFile.getName()+" 写入如下内容 :"); System.out.println(heardMess); } catch(IOException exp){System.out.println(exp.toString());} }}