1类图
2java示例
{ main([] args) { Factory factory StudentFactory(); Person p1factory.getPerson(); (p1.getName()p1.getName().equals()){ p1.setName(); p1.setAge(); } Person p2factory.getPerson(); System.out.println(p2.getName()p2.getAge()); } }
{ Person getPerson( sno); }
Factory { Map,Person personMap HashMap,Person(); Person getPerson( sno) { Person ppersonMap.get(sno); (p){ p Student(sno); personMap.put(sno, p); } p; } }
{ name; age; setName( name) { .name name; } setAge( age) { .age age; } getAge() { age; } getName() { name; } }
Person { sno; Student( sno){ .snosno; } }