3 ms·
"Objects" have nothing to do with taxonomies, or where you put your state. Objects are only an answer to the question: where does the computation that updates t
by derefr 8y ago
"Objects" have nothing to do with taxonomies, or where you put your state. Objects are only an answer to the question: where does the computation that updates the state live?
Or, to put that another way: objects are minimal abstract computers.
Picture the same situation, except instead of objects, we've got computers. Three, in fact. One that's running a "knife service", one running a "cheese service", and one that's an RDBMS.
To cut the cheese in this Service-Oriented Architecture, what do you do?
Well, probably, you start by getting a cheese handle from the cheese service, and getting a knife handle from the knife service.
Then, very likely, you're going to tell the knife service—passing the knife handle and the cheese handle—to cut the cheese.
And the knife service is in turn going to talk to the cheese service—passing the cheese handle—telling it that the cheese should get cut, and specifying what the knife wants to do.
If the cheese succeeds in getting cut, then it returns updated cheese to the knife, which returns {success, updated cheese} to you.
Why all that? Because:
• Only the knife service contains the code—the business logic—to know how knives work, so only the knife can construct a description of the precise way that the knife is going to try to cut cheese.
• And only the cheese service contains the code—the business logic—to know what cheese is like as a material, so only the cheese can evaluate the attempt by the knife to cut it.
OOP is just like SOA, except that the fact of what "service" (i.e. class) you should talk to about a given object-handle is encapsulated within the object, and is potentially even a mutable property of that object. (Maybe cutting your cheese with a hot knife results in your cheese-handle mutating into a raclette-handle.)
Also note that at no point did I say where the state for anything is. It's in the RDBMS, maybe. Or maybe the durable state for all knives is inside the knife service, and the durable state for all cheeses is inside the cheese service. It's kind of irrelevant. (That's another thing about objects: they entirely encapsulate their state, so it doesn't matter where it is. This allows for e.g. distributed object frameworks where you have local objects that stand in as proxies for remote objects somewhere else. Just like in an SOA, you can have network proxies that stand in for services somewhere else.)