OOP : @madvirus, : madvirus@madvirus.net : @madvirus : madvirus@madvirus.net ) ) ) 7, 3, JSP 2
? 3 case R.id.txt_all: switch (menu_type) { case GROUP_ALL: showrecommend("month"); case GROUP_MY: type = "all"; showmygroup(type, "newest"); case R.id.txt_share: switch (menu_type) { case GROUP_ALL: showgroup("newest"); case GROUP_MY: type = "share"; showmygroup(type, "share"); 4
case R.id.txt_all: switch (menu_type) { case GROUP_ALL: showrecommend("month"); case GROUP_MY: type = "all"; showmygroup(type, "newest"); case GROUP_FAVORITE: type = ""; showfavorite(type, "newest"); case GROUP_LIST: type = ""; showlist(type); case GROUP_WORDS: type = ""; showwordlist(type); case R.id.txt_share: switch (menu_type) { case GROUP_ALL: showgroup("newest"); case GROUP_MY: type = "share"; showmygroup(type, "share"); case GROUP_FAVORITE: type = "program"; showfavorite(type, "newest"); case GROUP_LIST: type = "PROGRAM"; showlist(type); case GROUP_WORDS: type = "PROGRAMCONTENT"; showwordlist(type); 5???? case R.id.txt_all: switch (menu_type) { case GROUP_ALL: showrecommend("month"); case GROUP_MY: type = "all"; showmygroup(type, "newest"); case GROUP_FAVORITE: type = ""; showfavorite(type, "newest"); case GROUP_LIST: type = ""; showlist(type); case GROUP_WORDS: type = ""; showwordlist(type); case R.id.txt_share: switch (menu_type) { case GROUP_ALL: showgroup("newest"); case GROUP_MY: type = "share"; showmygroup(type, "share"); case GROUP_FAVORITE: type = "program"; showfavorite(type, "newest"); case GROUP_LIST: type = "PROGRAM"; showlist(type); case GROUP_WORDS: type = "PROGRAMCONTENT"; showwordlist(type); case R.id.txt_n_share: switch (menu_type) { case GROUP_ALL: showgroup("hits"); case GROUP_MY: type = "unshare"; showmygroup(type, "unshare"); case GROUP_FAVORITE: type = "movie"; showfavorite(type, "newest"); case GROUP_LIST: type = "MOVIE"; showlist(type); case GROUP_WORDS: type = "MOVIE"; showwordlist(type); case R.id.txt_group: switch (menu_type) { case GROUP_ALL: showgroup("hits"); case GROUP_MY: type = "unshare"; showmygroup(type, "unshare"); case GROUP_FAVORITE: type = "group"; showfavorite(type, "newest"); case GROUP_LIST: type = "GROUP"; showlist(type); case GROUP_WORDS: type = "GROUP"; showwordlist(type); case R.id.btn_delete: if (btn_select.isshown()) { switch (menu_type) { case GROUP_MY: delete(); case GROUP_FAVORITE: deletefavorite(); else { hidebutton(); switch (menu_type) { case GROUP_MY: setmygrouplist(true); case GROUP_FAVORITE: setfavoritelist(true); 6
TOC vs 7 8
? 9 ( ) 10 객체지향 기초 소개, 최범균, 본 자료의 무단 배포를 금합니다.
11 /, 12
Object Oriented 13 14
15 16
(Object) TV 17, C# public class TV { public void increasevolume() { public void decreasevolume() { TV tv = new TV(); tv.increasevolume(); 18
/ (Responsibility) DB 19 SOLID S: Single Responsibility Principle HomeActivity HomeActivity TopFeatured ListView BottomBest ListView 20
( ) ( ) / ( ) 21 22
(Encapsulation) 23 : - public class ProceduralStopWatch { public long starttime; // (1/1000 ) public long stoptime; // 1/1000 public long getelapsedtime() { return stoptime - starttime; ProceduralStopWatch stopwatch = new ProceduralStopWatch(); stopwatch.starttime = System.currentTimeMillis(); // // stopwatch.stoptime = System.currentTimeMillis(); // long elapsedtime = stopwatch.getelapsedtime(); // 24
public class ProceduralStopWatch { public long starttime; public long stoptime; public long startnanotime; public long stopnanotime; - public long getelapsednanotime() { return stopnanotime - startnanotime; ProceduralStopWatch stopwatch = new ProceduralStopWatch(); stopwatch.startnanotime = System.nanoTime(); // // stopwatch.stopnanotime = System.nanoTime(); // long elapsedtime = stopwatch.getelapsednanotime(); // 25-26
- / public class StopWatch { private long starttime; private long stoptime; public void start() { starttime = System.currentTimeMillis(); public void stop() { stoptime = System.currentTimeMillis(); public Time getelapsedtime() { return new Time(stopTime - starttime); 27 / StopWatch stopwatch = new StopWatch(); stopwatch.start(); // starttime, // stopwatch.stop(); // stoptime, Time time = stopwatch.getelapsedtime(); // long time.getmillitime(); 28
- public class StopWatch { private long starttime; private long stoptime; public void start() { starttime = System.nanoTime(); public void stop() { stoptime = System.nanoTime(); public Time getelapsedtime() { return new Time(stopTime - starttime); public class Time { private long t; public Time(long t) { this.t = t; public long getmillitime() { return t / 1000000L; public long getnanotime() { return t; 29 StopWatch stopwatch = new StopWatch(); stopwatch.start(); // stopwatch.stop(); Time time = stopwatch.getelapsedtime(); time.getnanotime(); ProceduralStopWatch stopwatch = new ProceduralStopWatch(); stopwatch.startnanotime = System.nanoTime(); // // stopwatch.stopnanotime = System.nanoTime(); // long elapsedtime = stopwatch.getelapsednanotime(); // 30
-! 31 : Tell, Don't Ask 32
Tell, Don't Ask /,, if (member.getexpiredate().gettime() < System. System.currentTimeMillis) { if (member.isexpired()) { 33 Law of Demeter CQRS(Command Query Responsibility Segregation) 34
35 Polymorphism? Java/C# ' Inheritance' Motorcycle start() ZetMotorcycle start() ZetEngine zeton() AirPlane ZetMotorcycle zm = new ZetMotorcycle(); zm.start(); zm.zeton(); Motorcycle mc = zm; mc.start(); ZetEngine ze = zm; ze.zeton(); ZetEngine ap = new AirPlane(); ap.zeton(); 36
public class ZetEngine { public class AirPlane extends ZetEngine { AirPlane ap = new AirPlane(); ap.zeton(); public interface ZetEngine { public void zeton(); public interface Motorcycle { public void start(); public class ZetMotorcycle implements ZetEngine, Motorcycle { ZetMotorcycle zm = new ZetMotorcycle(); ZetEngine ze = zm; Motorcycle mc = zm; 37 Abstraction / / DB FTP SCP 38
( ) class FtpLogCollector { private String ftpserver; class FtpLogSet { class DBLogCollector { private String jdbcurl; class DBrowLogSet { interface LogCollector { LogSet collect(); interface LogSet { Iterator iterator(); 39 : class FtpLogCollector implements LogCollector { private String ftpserver; public LogSet collect() { class FtpLogSet implements LogSet { class DBLogCollector implements LogCollector { private String jdbcurl; public LogSet collect() { class DBrowLogSet implements LogSet { 40
LogCollector collector = new FtpLogCollector(ftpServer); LogSet logset = collector.collect(); Iterator iter = logset.iterator(); 41, DB 42
/ 43, FtpLogCollector collector = new FtpLogcollector(); FtpLogSet logset = collector.collect(); Iterator iter = logset.iterator(); FileLogCollector collector = new FileLogcollector(); FileLogSet logset = collector.collect(); Iterator iter = logset.iterator(); XXXLogCollector collector = new XXXLogcollector(); XXXLogSet logset = collector.collect(); Iterator iter = logset.iterator(); 44
( ) LogCollector collector = ; LogSet logset = collector.collect(); Iterator iter = logset.iterator(); LogCollector collector = ; LogSet logset = collector.collect(); Iterator iter = logset.iterator(); LogCollector collector = ; LogSet logset = collector.collect(); Iterator iter = logset.iterator(); 45 / : LogCollector collector = LogCollectorFactory.create(); LogSet logset = collector.collect(); Iterator iter = logset.iterator(); LogCollector collector = LogCollectorFactory.create(); LogSet logset = collector.collect(); Iterator iter = logset.iterator(); LogCollector collector = LogCollectorFactory.create(); LogSet logset = collector.collect(); Iterator iter = logset.iterator(); 46
/ : ( )! / if-else?., 47 :Composition over inheritance 48
( ) public class LuggageCompartment extends ArrayList<Luggage> { private int restspce; public void add(luggage piece) { this.restspace -= piece.getsize(); super.add(piece); public void cancontain(luggage piece) { return this.restspace > piece.size(); LuggageCompoartment lc = new LuggageCompartment(); lc.add(new Luggage(10)); //!! restspace! lc.remove(someluggage); lc.extract(anyluggage); lc.cancontain(aluggage); // public void extract(luggage piece) { this.restspace += piece.getsize(); super.remove(piece); 49 IS-A!=, ArrayList is a AbstractList 50
(composition) public class LuggageCompartment { private List<Luggage> luggages = new ArrayList<Luggage>(); private int restspce; public void add(luggage piece) { restspace -= piece.getsize(); luggages.add(piece); public void cancontain(luggage piece) { return this.restspace > piece.size(); public void extract(luggage piece) { restspace += piece.getsize(); luggage.remove(piece); 51 public class Calculator { private PriceStrategy strategy; public Calculator(PriceStrategy strategy) { this.strategy = strategy; public interface PriceStrategy { void apply(money price); public class RegularCustomerStrategy this.strategy.apply(price); public class FirstCustomerStrategy PriceStrategy strategy = new RegularCustomerStrategy(); Calculator cal = new Calculator(strategy); cal.calculate(); Calculator PriceStrategy strategy = new FirstCustomerStrategy(); Calculator cal = new Calculator(strategy); cal.calculate(); 52
/ 53 Seekbar/ Seekbar/ 54
public class Player { private TitleView titleview; private RecListView reclistview; private FuncButtonView funcbuttonview; private ClipPointView clippointview; private Controller controller; private boolean viewvisible; private int mode = 0; private void togglevisibility () { if (!viewshowing) { if (mode == 0) { titleview.show(); reclistview.show(); else if (mode == 1) { controller.show(); else { // if-else hide() 55 public class Player { private TitleView titleview; private RecListView reclistview; private FuncButtonView funcbuttonview; private ClipPointView clippointview; private Controller controller; private boolean viewvisible; private int mode = 0; mode / private void togglevisibility () { if (!viewshowing) { if (mode == 0) { titleview.show(); reclistview.show(); else if (mode == 1) { controller.show(); else { // if-else hide() 56
Player public class Player { private TitleView titleview; private RecListView reclistview; private FuncButtonView funcbuttonview; private ClipPointView clippointview; private Controller controller; private boolean viewvisible; private int mode = 0; public class Player { private ViewLayout layout; private void ontouch() { layout.togglevisibility(); private void togglevisibility () { if (!viewshowing) { if (mode == 0) { titleview.show(); reclistview.show(); else if (mode == 1) { controller.show(); else { // if-else hide() public class ViewLayout { private TitleView titleview; private RecListView reclistview; private Controller controller; private boolean viewvisible; private int mode = 0; public void togglevisibility () { 57 View public class ViewLayout { private TitleView titleview; private RecListView reclistview; private FuncButtonView funcbuttonview; private ClipPointView clippointview; private Controller controller; private boolean viewvisible; private int mode = 0; public interface View { public void show(); public void hide(); public class TitleView implements View { public void togglevisibility () { if (!viewshowing) { else { public class Controllerimplements View { 58
View public class ViewLayout { private TitleView titleview; private RecListView reclistview; private FuncButtonView funcbuttonview; private ClipPointView clippointview; private Controller controller; private boolean viewvisible; private int mode = 0; public class ViewLayout { private Map<Position, View> viewmap; public void setview( Position pos, View view) { viewmap.put(pos, view); private public void togglevisibility () { if (!viewshowing) { else { public void togglevisibility() { for (View view : viewmap.values()) { if (!viewshowing) { view.show(); else { view.hide(); viewshowing =!viewshowing; 59 ViewLayout public class ViewLayout { private Map<Position, View> viewmap; public void setview( Position pos, View view) { viewmap.put(pos, view); private public interface ViewLayout { public void togglevisibility(); public class BorderViewLayout implements ViewLayout { private Map<Position, View> viewmap; public void togglevisibility() { for (View view : viewmap.values()) { if (!viewshowing) { view.show(); else { view.hide(); viewshowing =!viewshowing; public void setview( Position pos, View view) { viewmap.put(pos, view); private public void togglevisibility() { 60
Player View View Player Player Layout Player View View BorderViewLayout 61 62
High Cohesion ( )!, Low Coupling ( ) 63 : <<<<,,, C# / Tell, Don't Ask Program To Interface Composition over Inheritance 64
UML, : SOLID (GoF ): TDD! Clean Code Implementation Pattern 65? 66