Bc. Matej Kováč Vedúci projektu: prof. Ing. Pavol Návrat, PhD. Refaktorizácia softvérových systémov s podporou kontextového odporúčania Bc. Matej Kováč Vedúci projektu: prof. Ing. Pavol Návrat, PhD.
Refaktorizácia a návrhové vzory GoF, Design Patterns: Elements of Reusable Object-Oriented Software M. Fowler, Refactoring: Improving the design of existing code J. Kerievsky, Refactoring to Patterns
Ciele práce Vytvorenie prístupu pre identifikáciu nedostatkov v návrhu existujúcich systémov, ktoré je možné odstrániť zavedením návrhových vzorov Zakomponovanie prístupu do existujúceho vývojového prostredia
JDeodorant: Refaktorizácia so vnášaním polymorfizmu N. Tsantalis and A. Chatzigeorgiou, Identification of refactoring opportunities introducing polymorphism, Elsevier, 2009.
public class Square extends Shape { private double side; public double calculateArea() { return side * side; }
public class CarStore { public Car createCar(EquipmentClass equipmentClass) { // deklarácie premenných a pod. switch (equipmentClass) { case COMFORT: engine = new DieselEngine(); seat = new FabricSeat(); transmission = new ManualTransmission(); break; case SPORT: engine = new PetrolEngine(); seat = new SportSeat(); transmission = new DualClutchTransmission(); case LUXURY: engine = new HybridEngine(); seat = new LeatherSeat(); transmission = new AutomaticTransmission(); } return new Car(engine, seat, transmission); aaa}
public class CarStore { public Car createCar(EquipmentClass equipmentClass) { // deklarácie premenných a pod. switch (equipmentClass) { case COMFORT: engine = new DieselEngine(); seat = new FabricSeat(); transmission = new ManualTransmission(); break; case SPORT: engine = new PetrolEngine(); seat = new SportSeat(); transmission = new DualClutchTransmission(); case LUXURY: engine = new HybridEngine(); seat = new LeatherSeat(); transmission = new AutomaticTransmission(); } return new Car(engine, seat, transmission); aaa}
Abstract Factory
Abstract Factory Factory Method Engine Seat Transmission COMFORT 1 switch (equipmentClass) { case COMFORT: engine = new DieselEngine(); seat = new FabricSeat(); transmission = new ManualTransmission(); break; case SPORT: engine = new PetrolEngine(); transmission = new DualTransmission(); case LUXURY: engine = new HybridEngine(); seat = new LeatherSeat(); transmission = new AutomaticTransmission(); } switch (equipmentClass) { case COMFORT: engine = new DieselEngine(); seat = new FabricSeat(); break; case SPORT: engine = new PetrolEngine(); case LUXURY: engine = new HybridEngine(); something = new SomethingElse(); } Engine Seat Transmission COMFORT 1 SPORT LUXURY Engine Seat COMFORT 1 SPORT LUXURY Abstract Factory Factory Method
Builder public class Car { private String model; // povinný atribút private String brand; // povinný atribút private Color color; // nepovinný atribút private EquipmentClass equipment; // nepovinný atribút public Car(String model, String brand) { this(model, brand, null); } public Car(String model, String brand, Color color) { this(model, brand, color, null); public Car(String model, String brand, Color color, EquipmentClass equipment) { this.model = model; this.brand = brand; this.color = color; this.equipment = equipment;
Builder public class CarSeller { private Car car; public void prepareCar() { Car car = new Car(); car.setColor(new Color(255,255,255)); car.setBrand("Audi"); car.setModel("A3"); car.setId(1L); car.setWheels(4); } Joshua Bloch. Effective Java. Java Series. Pearson Education, 2008.
Mediator
Plán Podpora pre nasadenie inštancií odporúčaných vzorov Overenie riešenia
Zhrnutie Odporúčané vzory: Odporúčania na úrovni: Abstract Factory Builder Factory Method Mediator Odporúčania na úrovni: Kompilačných jednotiek (.java súbor) Balíkov Projektov