Presentation in Bulgarian about SOLID design principles.
Presented at PlovDev Conference 2014, ProxiAD office in Bulgaria (multiple times) and at an event for Woman Who Code in Sofia in 2017
4. kgolev.com@kotseto
S ingle Responsibility Principle
O pen-Closed Principle
L iskov Substitution Principle
I nterface Segregation Principle
D ependency Inversion Principle
11. kgolev.com@kotseto
class TaxiService {
void orderTaxi(String phone, String address) {
if (phone.length() < 7) {
throw new BadPhoneNumberException
(Phone not valid!");
}
taxiPool.sendTaxi(address);
smsClient.sendMessage(phone,
"Your taxi is on the way!");
}
12. kgolev.com@kotseto
class TaxiService_V2 {
void orderTaxi(String phone, String address) {
if (phone.length() < 7
&& phone.length() > 12) { // <-- mistake
throw new BadPhoneNumberException
(Phone not valid!");
}
taxiPool.sendTaxi(address);
smsClient.sendMessage(phone,
Your taxi is on the way!");
}
14. kgolev.com@kotseto
public class {
public boolean phoneIsNotValid(String phone) {
return phone.length() < 7
|| phone.length() > 12;
}
}
15. kgolev.com@kotseto
class TaxiService_V3 {
void orderTaxi(String phone, String address) {
if (smsService.phoneIsNotValid(phone)) {
throw new BadPhoneNumberException
("Phone not valid!");
}
taxiPool.sendTaxi(address);
smsService.sendMessage(phone,
Your taxi is on the way!");
}
55. kgolev.com@kotseto
Opel dieselCar = new Opel(new OpelDieselEngine());
dieselCar.start();
Opel gasolineCar = new Opel(new OpelGasolineEngine());
dieselCar.start();