lundi 19 novembre 2018

why is it that bad to change client code than the actual code?

My questions will be in a strong bold text.

I don't know why but I have a serious problem. I've been following design patterns, but they make me crazy throughout the whole day.

Basically, what all patterns aim is abstraction and doing something so that it's easy to add features without changing code. That's where my problem is. WHat they say is it's bad to change client code. What is the client code? why is it too bad to change it?

enter image description here

Look at the picture. this man has 3 classes, LogFile, LogDatabase, LogWebService. ALl of them implement Logger class which has the log($data) function as abstract. now look at the App class and then how he uses it. This man says that It's a bad code because class App and LogToFile are tightly coupled. if He wants to use DatabaseLog class, he would have to go to that log function and change LogToFile to DatabaseLog. Then what? why is it that bad at all? The solution he made is by passing Logger class as the second argument to App's log function.

Aucun commentaire:

Enregistrer un commentaire