上充大¥Implementation of UML Visibility in Java SHANGHAI JIAO TONG UNIVERSITY Tournament maxNumPlayers:int getMaxNumPlayers():int getPTayers():List acceptPTayer(p:Player) emovePlayer(p:Player) sPlayerAccepted(p:Player):boolean public class Tournament private int maxNumPlayers; public Tournament(League 1,int maxNumPTayers) public int getMaxNumPlayers(){...} public List getPlayers(){... public)void acceptPlayer(Player p){...}; public void removePlayer(Player p){.; public boolean isPlayerAccepted(Player p) {}; Software Engineering
Software Engineering Implementation of UML Visibility in Java public Tournament(League l, int maxNumPlayers) public int getMaxNumPlayers() {…}; public List getPlayers() {…}; public void acceptPlayer(Player p) {…}; public void removePlayer(Player p) {…}; public boolean isPlayerAccepted(Player p) {…}; Tournament - maxNumPlayers: int + acceptPlayer(p:Player) + removePlayer(p:Player) + getMaxNumPlayers():int + getPlayers(): List + isPlayerAccepted(p:Player):boolean public class Tournament { private int maxNumPlayers;
上大Information Hiding Heuristics SHANGHAI JIAO TONG UNIVERSITY Carefully define the public interface for classes as well as subsystems(facade) Always apply the "Need to know"principle. Only if somebody needs to access the information,make it publicly possible,but then only through well defined channels, so you always know the access. The fewer an operation knows the less likely it will be affected by any changes the easier the class can be changed Trade-off:Information hiding vs efficiency Accessing a private attribute might be too slow(for example in real-time systems or games) Software Engineering
Software Engineering Information Hiding Heuristics Carefully define the public interface for classes as well as subsystems (façade) Always apply the “Need to know” principle. • Only if somebody needs to access the information, make it publicly possible, but then only through well defined channels, so you always know the access. The fewer an operation knows • the less likely it will be affected by any changes • the easier the class can be changed Trade-off: Information hiding vs efficiency • Accessing a private attribute might be too slow (for example in real-time systems or games)
上大Information Hiding Design Principles SHANGHAI JIAO TONG UNIVERSITY Only the operations of a class are allowed to manipulate its attributes Access attributes only via operations. Hide external objects at subsystem boundary Define abstract class interfaces which mediate between system and external world as well as between subsystems 国 Do not apply an operation to the result of another operation. Write a new operation that combines the two operations. Software Engineering
Software Engineering Information Hiding Design Principles Only the operations of a class are allowed to manipulate its attributes • Access attributes only via operations. Hide external objects at subsystem boundary • Define abstract class interfaces which mediate between system and external world as well as between subsystems Do not apply an operation to the result of another operation. • Write a new operation that combines the two operations