什么是架构?
把所有需要完成的工作分成多份不同的工作,不同的人根据自己的特长做适合自己的工作而不必去做所有的工作,人与人之间通过沟通(不同的工作的人之间的沟通可能是不同的)构成有机的整体,从而是所有的工作完成。比如社会上有农民,医生,警察,老师,商人等等不同的角色,不需要每个人都去做生产,诊断,教学等所有工作,每种职业做好自己的工作就可以,通过交易和沟通得到粮食,安全保障和教育等资源。
用MVC模式分析自己家庭架构:
家庭体系架构图:
Family.java
public class Family { private String rollNo; private String name; private String name2; private String name3; private String name4; private String name5; private String bao; private String zuo; private String shua; private String buy; public String getRollNo() { return rollNo; } public void setRollNo(String rollNo) { this.rollNo = rollNo; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getBao() { // TODO Auto-generated method stub return bao; } public void setBao(String bao) { this.bao = bao; } public void setZuo(String zuo) { this.zuo = zuo; } public String getZuo() { // TODO Auto-generated method stub return zuo; } public void setShua(String shua) { this.shua = shua; } public String getShua() { // TODO Auto-generated method stub return shua; } public void setBuy(String buy) { this.buy = buy; } public String getBuy() { // TODO Auto-generated method stub return buy; } public void setName2(String name2) { this.name2 = name2; } public String getName2() { // TODO Auto-generated method stub return name2; } public void setName3(String name3) { this.name3 = name3; } public String getName3() { return name3; } public void setName4(String name4) { this.name4 = name4; } public String getName4() { return name4; } public void setName5(String name5) { this.name5 = name5; } public String getName5() { return name5; } }
FamilyController.java
public class FamilyController { private Family model; private FamilyView view; public FamilyController(Family model, FamilyView view){ this.model = model; this.view = view; } public void setFamilyName(String name){ model.setName(name); } public void setSName(String name2){ model.setName2(name2); } public void setWName(String name3){ model.setName3(name3); } public void setW2Name(String name4){ model.setName4(name4); } public void setFBName(String name5){ model.setName5(name5); } public String getFamilyName(){ return model.getName(); } public String getSName(){ return model.getName2(); } public String getWName(){ return model.getName3(); } public String getW2Name(){ return model.getName4(); } public String getFBName(){ return model.getName5(); } public void setFamilyBao(String bao){ model.setName(bao); } public String getFamilyBao(){ return model.getBao(); } public void setFamilyRollNo(String rollNo){ model.setRollNo(rollNo); } public String getFamilyRollNo(){ return model.getRollNo(); } public void setFamilyZuo(String zuo){ model.setName(zuo); } public String getFamilyZuo(){ return model.getZuo(); } public void setFamilyShua(String shua){ model.setName(shua); } public String getFamilyShua(){ return model.getShua(); } public void setFamilyBuy(String buy){ model.setName(buy); } public String getFamilyBuy(){ return model.getBuy(); } public void View(){ view.printFamilyDetails(model.getName(), model.getRollNo()); } public void View2(){ view.printFamilyDetails(model.getName2(), model.getBao()); } public void View3(){ view.printWDetails(model.getName3(), model.getZuo()); } public void View4(){ view.printW2Details(model.getName4(), model.getShua()); } public void View5(){ view.printFBDetails(model.getName5(), model.getBuy()); } }
FamilyView.java
public class FamilyView { public void printFamilyDetails(String familyName, String familyRollNo){ System.out.println("Family: "); System.out.println("事件: " + familyName); System.out.println("家务: " + familyRollNo); } public void printSDetails(String familyName2, String familyBao){ System.out.println("Family: "); System.out.println("事件: " + familyName2); System.out.println("家务: " + familyBao); } public void printWDetails(String familyName3, String familyZuo){ System.out.println("Family: "); System.out.println("事件: " + familyName3); System.out.println("家务: " + familyZuo); } public void printW2Details(String familyName4, String familyShua){ System.out.println("Family: "); System.out.println("事件: " + familyName4); System.out.println("家务: " + familyShua); } public void printFBDetails(String familyName5, String familyBuy) { System.out.println("Family: "); System.out.println("事件: " + familyName5); System.out.println("家务: " + familyBuy); } }
MVCclient.java
public class MVCclient { public static void main(String[] args) { Family model = retrievefamilyFromDatabase(); FamilyView view = new FamilyView(); FamilyController controller = new FamilyController(model, view); controller.setFamilyName("地脏了"); controller.View(); controller.setSName("孩子哭了"); controller.View2(); controller.setWName("到饭点了"); controller.View3(); controller.setW2Name("吃完饭了"); controller.View4(); controller.setFBName("没面了"); controller.View5(); } private static Family retrievefamilyFromDatabase(){ Family family = new Family(); family.setRollNo("妈妈拿扫帚扫地"); family.setBao("嫂子抱起孩子"); family.setZuo("我帮妈妈做饺子"); family.setShua("妈妈让我去刷碗"); family.setBuy("哥哥和爸爸去买粮食"); return family; }
原文:https://www.cnblogs.com/2205254761qq/p/12329120.html