Object-oriented – What are the advantages of strictly maintaining separate data | algorithm | interface layers

layersobject-oriented

I always separate the user interface from other functionality in my programs – its the way I have been taught, and it has obvious advantages since you can change the interface but keep the same functionality.

However, I've come across some programmers who strictly separate data, algorithms and interface. So the data objects which hold the data in volatile memory have only fields/properties and their getters and setters. Any algorithms are kept in a separate class.

In my view the main disadvantage of this is that the algorithm classes usually need full access to the data in the data classes. You might want to have a more functional class which you create with lots of data but then objects from other classes can only get at that data in specialised ways.

Best Answer

It's called a Plain Old Data Structure (PODS). They are fairly common in places where data first enters a system from an external source, like a database. In effect their single responsibility is to abstract that external data into a form that's easier for higher layers to consume.

In other words, it allows programmers of higher layers to work with familiar native objects rather than having to sprinkle accesses to the external source throughout the code. That data is read into the system in one place, and only that one place must change if the interface to the external source changes.

Like any principle, it can be taken too far. If they're commonly using a PODS on internal-only data, it's probably misguided in OOP. Note however that passing around a PODS is a fairly common pattern in functional programming, for better or worse.

Related Topic