&扇 0o2 Nice things of OOP UNIVE 11 ▣Aodular structure 口Reuse ▣Class ▣Design patterns ▣Framework Institute of Computer Software 2022-2-27 Nanjing University
Nice things of OOP Modular structure Reuse Class Design patterns Framework 2022-2-27 Institute of Computer Software Nanjing University 11
&扇 Limitations of O○P UNIVER 12 Crosscutting concerns Some things cannot be modeled well in object hierarchies!! Institute of Computer Software 2022-2-27 Nanjing University
Limitations of OOP 2022-2-27 Institute of Computer Software Nanjing University 12 Some things cannot be modeled well in object hierarchies!!
A motivating example:Tracing 102 UNIVE 13 class TraceSupport TraceSupport staticint TRACELEVEL 0; 个个下 static oteced Printstream stream null; static protected int callDepth =-1; scvoid init(PrintStreams)(stream=_s;} sacoi traceEntry(String str){ (TRACELEVEL =0)n; callDepth++; printEntering(str); staticvoid traceExit(String str){ (TRACELEVEL =0) class Point{ callDepth--; void set (int x,int y){ printExiting(str); TraceSupport.traceEntry("Point.set); thsX三x,this.y=y, TraceSupport.traceExit("Point.set"); Institute of Computer Software 2022-2-27 Nanjing University
A motivating example: Tracing 2022-2-27 Institute of Computer Software Nanjing University 13 class Point{ void set (int x, int y){ TraceSupport.traceEntry(“Point.set”); this.x =x; this.y=y; TraceSupport.traceExit(“Point.set”); } }
Java API Example 102 14 package java.io; public class File implements java.io.Serializablef private String path; public boolean exists(){ SecurityManager security System.getSecurityManager(); if(security!=-nul)以 security.checkRead(path); Same code repeated return exits0(); 16 times in java.io.File public boolean canRead(){ SecurityManager security System.getSecurityManager(); if(security!=nul以 security.checkRead(path); } return canRead0(); Institute of Computer Software 2022-2-27 Nanjing University
Java API Example 2022-2-27 Institute of Computer Software Nanjing University 14 package java.io; public class File implements java.io.Serializable{ private String path; … public boolean exists(){ SecurityManager security = System.getSecurityManager(); if(security!=null){ security.checkRead(path); } return exits0(); } public boolean canRead(){ SecurityManager security = System.getSecurityManager(); if(security!=null){ security.checkRead(path); } return canRead0(); } Same code repeated 16 times in java.io.File
&扇 1002 Crossing cutting concerns UNIVE 15 Crosscutting concerns Limitations of OOP: Some things cannot be modeled well in object hierarchies Institute of Computer Software 2022-2-27 Nanjing University
Crossing cutting concerns 2022-2-27 Institute of Computer Software Nanjing University 15