最病 A Nice things of OOP 口 Modular structure R euse a Class a Design patterns a Framework Institute of Computer Software 2021/1/27 Nanjing University
Nice things of OOP Modular structure Reuse Class Design patterns Framework 2021/1/27 Institute of Computer Software Nanjing University 11
最病 E Limitations of OOP Crosscutting concerns Some things cannot be modeled well in object hierarchies! Institute of Computer Software 2021/1/27 Nanjing University
Limitations of OOP 2021/1/27 Institute of Computer Software Nanjing University 12 Some things cannot be modeled well in object hierarchies!!
最病 E motivating example: Tracing Lass Trace Support t TraceSupport tatic int TRACELEVEL =0 tatic proteated Printstream stream null tatic proteated int callDepth =-1 static void init(Printstream s)[stream= si) traceEntry(String st (TRACELEVEL 0) return callDepth++ tEntering(str)i tatic void traceExit(String str) (TRACELEVEL 0)ret class Point( callDepth-- void set (int x, int yr printExiting(str) Trace Support. traceEntry(Pointset) this X =X this y=y Trace Support. traceExit(Point set); Institute of Computer Software 2021/1/27 Nanjing University
A motivating example: Tracing 2021/1/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”); } }
最病 A Java API Example package java. io public class File implements java. io Serializable private String path public boolean exists Security Manager security System getSecurity Manager( if(security !=null security checkRead(path) Same code repeated return exits 16 times in java. io. File public boolean canReado Security Manager security System getSecurity Manager(? if(security !=null) security. checkRead(path) return can Readoo Institute of Computer Software 2021/1/27 Nanjing University
Java API Example 2021/1/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
最病 o Crossing cutting concerns Crosscutting concerns Limitations of ooP Some things cannot be modeled well in object hierarchies Institute of Computer Software 2021/1/27 Nanjing University
Crossing cutting concerns 2021/1/27 Institute of Computer Software Nanjing University 15