Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service-Orientation vs Object-Orientation - can they coexist?

There's been a lot of interest in Service-Oriented Architecture (SOA) at my company recently. Whenever I try to see how we might use it, I always run up against a mental block. Crudely:

  • Object-orientation says: "keep data and methods that manipulate data (business processes) together";

  • Service-orientation says: "keep the business process in the service, and pass data to it".

Previous attempts to develop SOA have ended up converting object-oriented code into data structures and separate procedures (services) that manipulate them, which seems like a step backwards.

My question is: what patterns, architectures, strategies etc. allow SOA and OO to work together?


Edit: The answers saying "OO for internals, SOA for system boundaries" are great and useful, but this isn't quite what I was getting at.

Let's say you have an Account object which has a business operation called Merge that combines it with another account. A typical OO approach would look like this:

Account mainAccount = database.loadAccount(mainId); Account lesserAccount = database.loadAccount(lesserId);  mainAccount.mergeWith(lesserAccount);  mainAccount.save(); lesserAccount.delete(); 

Whereas the SOA equivalent I've seen looks like this:

Account mainAccount = accountService.loadAccount(mainId); Account lesserAccount = accountService.loadAccount(lesserId);  accountService.merge(mainAccount, lesserAccount); // save and delete handled by the service 

In the OO case the business logic (and entity awareness thanks to an ActiveRecord pattern) are baked into the Account class. In the SOA case the Account object is really just a structure, since all of the business rules are buried in the service.

Can I have rich, functional classes and reusable services at the same time?

like image 910
Dan Vinton Avatar asked Jan 14 '09 12:01

Dan Vinton


People also ask

What is major difference between object-oriented paradigm and service oriented?

SOA uses services to build systems. OOP uses objects to build systems, and it tends marry data and behavior. Services tend to separate data from behavior. In an SOA, the separation between data and behavior is often obvious.

Why is object orientation needed reason?

Benefits of OOP OOP language allows to break the program into the bit-sized problems that can be solved easily (one object at a time). The new technology promises greater programmer productivity, better quality of software and lesser maintenance cost. OOP systems can be easily upgraded from small to large systems.

What is service-orientation outline common principles of service-orientation?

A Service Oriented Architecture (SOA) is an architectural pattern in computer software design in which application components provide services to other components via a communications protocol, typically over a network. The principles of service-orientation are independent of any product, vendor or technology.


2 Answers

My opinion is that SOA can be useful, at a macro level, but each service probably still will be large enough to need several internal components. The internal components may benefit from OO architecture.

The SOA API should be defined more carefully than the internal APIs, since it is an external API. The data types passed at this level should be as simple as possible, with no internal logic. If there is some logic that belongs with the data type (e.g. validation), there should preferably be one service in charge of running the logic on the data type.

like image 164
Avi Avatar answered Sep 30 '22 11:09

Avi


SOA is a good architecture for communicating between systems or applications.

Each application defines a "service" interface which consists of the requests it will handle and the resposes expected.

The key points here are well defined services, with a well defined interface. How your services are actually implemnted is irrelevent as far as SOA is concerned.

So you are free to implement your services uing all the latest and greatest OO tequniques, or any other methodoligy that works for you. ( I have seen extreme cases where the "service" is implmented by actual humans entering data on a screen -- yet everything was still text book SOA!).

like image 23
James Anderson Avatar answered Sep 30 '22 11:09

James Anderson