Anemic Domain Model, callbacks and missing language features

PHP Software Architecture Very often I see an object in a project that is basically just a data container. There is no functionality, only private properties and set of getters and setters. If you are lucky, there is some sort of validation in the setters for the inputs, but that is not always the case. And every time I see these object in PHP, I hear people call them Anemic Domain Models. However from my experience this is not always the case. They are just a symptom of a fundemental problem in PHP. There is no decend way to pass data around. You have so few data types in PHP. And the only way you can add more is to use objects. You need only positive integer? You can either check for the validity every single time you pass a regular integer around, or you can use an object. Need a valid phone number? Use an integer or string and always validate or use an object. Need an address? Use an array and validate not only the values of each key, but the existence of the keys themselves. Or use an object for that.…  přečtěte si více

MVPC - Introducing mSPV

MVC MVP Software Architecture Continuation of MVPC – Deeper look Nomenclature warning: This article uses several very similar terms that are context dependent and are very easy to confuse. Please refer to this loose definition list: Service – Any class registered in Nette Dependenty Injection Container (DIC) Business service – A special case of the generic service. Business services always have a model behind them. They serve as the access point to a model from the presenter. In this regard, they do not differ from a controller. Model – The data storage In the last article we ended up with the problem of multiple PV applications, written in different languages, communicationg with…  přečtěte si více

MVPC - Deeper look

MVC MVP Software Architecture Continuation of MVPC – Implementation Last time I talked about Nette in MVPC context. It was a good framework for websites, but it didn't work very well if the access point to your application was a CLI or an API. This time I will show you how to solve this issue and how to integrate Nette into MVPC designed application. PV vs. MC In The difference between presenter and controller article I have shown you 3 different presenters all collaborating with only one controller. Each of these presenter has to use its own view, since they are displaying completely different outputs. On the other hand there was need for only one model, since it's only the shared controller…  přečtěte si více

MVPC - Implementation

MVC MVP Software Architecture Continuation of MVPC – the difference between Presenter and Controller Nette and MVPC Nette is taken here as an example of a PHP web application framework I am the most familiar with. The same might or might not apply to any other framework in PHP or any other language. Nette framework is my web framework of choice. There are a few reasons for it, the most important are security by default and completely ready co AJAXful websites. But the most important feature of Nette for me, the one that makes it really fit into the MVPC design pattern, is its dependency injection container. But first let's talk about the building blocks of Nette and how they fit into MVPC. There are many ways how to measure what are the most prominent or most important parts of a framework. However Nette makes it easy for us. It is decomposed into several individual packages (each of which you can use on its own), and by combining them together with the help of several bridges, you get the whole framework.…  přečtěte si více

MVPC - the difference between Presenter and Controller

MVC MVP Software Architecture MVC or MVP? Why not both? Model-View-Controller, Model-View-Presenter. A lot of people use these terms interchangeably. You can see one or the other in the description of virtually any web application framework. But is there actually any difference between these two? Is Controller different from Presenter in any way or are they just a different name for the same thing? I used to think of them as synonyms. If someone asked me to describe the MVC or MVP pattern, I would describe them the same: Model – the persistance layer. How and where the data is stored and retrieved. View – the display layer. Where the data is structured for use by the user(intentionally avoiding the word „presented“). Basically the application's tem­plates (or ocassionally API definitions). Presenter/Con­troller – the logic layer. Desides what how to react to the user's request, what data to retrieve from the Model and how to present them using the appropriate View. For the Model and the View, the…  přečtěte si více