Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SOA principles over OOD in non-service code

Tags:

oop

soa

Our architect has spoken about using SOA techniques throughout our codebase, even on interfaces that are not actually hosted as a service. One of his requests is that we design our interface methods so that we make no assumptions about the actual implementation. So if we have a method that takes in an object and needs to update a property on that object, we explictly need to return the object from the method. Otherwise we would be relying on the fact that Something is a reference type and c# allows us to update properties on a reference type by default.

So:

public void SaveSomething(Something something)
{
  //save to database

  something.SomethingID = 42;
}

becomes:

public Something SaveSomething(Something something)
{
  //save to database

  return new Something
  {
    //all properties here including new primary key from db
  };
}

I can't really get my head around the benefits of this approach and was wondering if anyone could help?

Is this a common approach?

like image 358
Georgia Brown Avatar asked Apr 12 '10 12:04

Georgia Brown


People also ask

What are the important principles of SOA service oriented architecture?

Principles of Service-Oriented ArchitectureStandardized Service Contract: Services adhere to a service-description. A service needs to have some information that defines what the service is about. Loose Coupling: Services minimize dependencies on each other.

What is SOA used for?

SOA is an architectural style for building software applications that use services available in a network such as the web. It promotes loose coupling between software components so that they can be reused. Applications in SOA are built based on services.

What are the principles of SOA are not being automatically provided by Web service justify your answer?

The four principles identified as not being automatically provided by Web services are: service reusability. service autonomy. service statelessness.


1 Answers

I think your architect is trying to get your code to have fewer side effects. In your specific example, there isn't a benefit. In many, many cases, your architect would be right, and you can design large parts of your application without side effects, but one place this cannot happen is during operations against a database.

What you need to do is get familiar with functional programming, and prepare for your conversations about cases like these with your architect. Remember his/her intentions are most likely good, but specific cases are YOUR domain. In this case, the side effect is the point, and you would most likely want a return type of bool to indicate success, but returning a new type doesn't make sense.

Show your architect that you understand limiting side effects, but certain side effects must be allowed (database, UI, network access, et cetera), and you will likely find that he or she agrees with you. Find a way to isolate the desired side effects and make them clear to him or her, and it will help your case. Your architect will probably appreciate it if you do this in the spirit of collaboration (not trying to shoot holes in his or her plan).

A couple resources for FP:

  1. A great tutorial on Functional Programming
  2. Wikipedia's entry on Functional programming

Good luck, I hope this helps.

like image 118
Audie Avatar answered Sep 19 '22 17:09

Audie