In college I took on a class on modern physics, in which we learned about special relativity. I was completely blown away by how different frames of reference could actually observe physical properties of an object to be different and neither be incorrect. Over time, this concept has slowly been changing the way I program, to the point where now I tend to break up classes into 2 main categories, data objects and observing (function only) objects.
For the sake of this not becoming a elaborate and lengthy post for such a simple question, I'll try to explain what I mean through two examples.
First, take for instance this type of code, which I used to often write:
class Deck
{
private Card[] cards;
public void Shuffle()
{
// shuffle algorithm
}
// other deck related functions like draw, cut, etc...
}
I typically now write the same scenario as:
class Deck
{
// by intention, i just mean some kind of immutable collection of cards
private ReadonlyCollection<Card> _Cards;
public Card[] Cards { get { return this._Cards; } }
}
interface IDeckHandler
{
Deck Shuffle(Deck deck);
// other deck related functions like draw, cut, etc..
}
class Dealer : IDeckHandler
{
// IDeckHandler implementation
}
The Deck
is no longer responsible for implementing the functions which can act on it. Or to make it fit the terminology, the deck is just a set of values and the way in which it is observed is the responsibility of the observer. Naturally, there can be many observers who perform the actions differently.
For the second example, I'll use something which people I have tried to explain this to have had an easier time with. Take the situation where we have colored letters on colored paper which spell out a word. We have an agent whose responsibility it is to read the word on the paper. Now assume the agent is some type of color blind. The image being emitted from the paper is the same, but the perception could be different. The observer does not have intimate knowledge of the object and cannot modify it, only respond with an interpretation of it.
As I have stated, this concept drives many of my development decisions. So back to the question, is this a published type of programming and if so, can you point me to some literature on it? There are some common and uncommon scenarios I have run into which are difficult to make decisions for, and certainly some things I just haven't thought of or run into yet which would hopefully have been examined in literature.