According to this article, a model is not a class or object, but a layer for 3 concepts: domain objects, data mappers, services.
I get the difference between these, but I get confused when the word "factory" is being attached to "service": ServiceFactory. Or DataMapperFactory. Or persistence. Whats the difference between ServiceFactory and a single Service? Or when different classes implement Interfaces. I dont see the point of all this. To me it seems that its just too much unnecessary abstraction. Please forgive me if I am being ignorant, I just dont understand, YET ;)
For example, when talking interfaces, what will happen if i create a functionality called "plugins" where I will tell myself to always have the method "run" in every plugin class. This run method will be called by a model, and if it doesnt exist, a fatal error will be displayed by a PHP interpreter. Same will happen if i implement an interface. So whats the point of this extra work?
Another example of an addition to PHP that i just dont see why it should be used is namespaces. why do i need to use this feature, say place my DB classes in namespace Database, if at the end of the day, only one of those classes will be used at any given request. i dont see how names will get mixed up in an application so that it requires namespaces. a few good usable real world examples would be appreciated (no foo bars please). Same for interfaces.
Now, I totally see why I should use the keyword "extends" for some classes. Say i have lots of views and all of them use headers and subheaders as variables. So I could make a superclass, add protected variables header and subheader, and create specific views that extend the superclass, inheriting the protected variables. I totally see the usefulness here.
But not when it comes to: Interfaces, Factories, Persistence, or even UnitTesting.
Say my app works fine. Then I want to make a big change. I dont go about making this big change, coding the whole thing at once. No, I write small chunks of code at a time, see if that works, so that i can pinpoint the problem right away. Why waste time using UnitTesting?
Please forgive me if you interpret my lack of understanding as ignorance. I am curious and hungry for knowledge, so please, if you want to, take your time to give me real world examples on why Interfaces, Factories, Persistence, UnitTesting are a good idea.
I know I might get lots of downvotes for this, I just wanted to take all the things I dont understand under one single question.
Aucun commentaire:
Enregistrer un commentaire