public double total PricePart parts double total0 0

  • Slides: 23
Download presentation

예제 public double total. Price(Part[] parts) { double total=0. 0; for (int i=0; i<parts.

예제 public double total. Price(Part[] parts) { double total=0. 0; for (int i=0; i<parts. length; i++) total+=parts. get. Price(); return total; } public void rotate() {…} public void minimize(){…} public void maxmize() {…} public void draw(); {…} } 16

예제 public double total. Price(Part[] parts) { double total=0. 0; for (int i=0; i<parts.

예제 public double total. Price(Part[] parts) { double total=0. 0; for (int i=0; i<parts. length; i++) total+=parts. get. Price(); return total; } public void rotate() {…} public void minimize(){…} public void maxmize() {…} 메모리 가격에 프 리미엄을 붙이는 void public 변동이 있는 경우 에는? draw(); {…} } 17

예제 public void rotate() {…} public void minimize(){…} public void maxmize() {…} public class

예제 public void rotate() {…} public void minimize(){…} public void maxmize() {…} public class Memory extends Part { public double get. Price() public void { return 2. 0*price; draw(); {…} } }} public class Part { protected double price; public Part(double price) {this. price=price; } public void set. Price(double Price) {this. price=price; } public double get. Price() {return price; } } 메모리 가격에 프 리미엄을 붙이는 변동이 있는 경우 에는? 18

Strategy 패턴 public void rotate() {…} public void minimize(){…} public void maxmize() {…} public

Strategy 패턴 public void rotate() {…} public void minimize(){…} public void maxmize() {…} public void draw(); {…} public class } Price. Policy { public class Part { protected double price; private Price. Policy p public Part(double price) {this. price=price; } public void set. Price(double Price) {this. price=price; } public double get. Price() {return p. get. Price(price); } public set. Price. Policy(Price. Policy p) {this. p=p; } } private double f; public Pricey. Policy(double f) {this. f=f; } public double get. Price(double p) {return p*f; } 19

LSP 23

LSP 23