Using SOA principles over OOD in non-maintenance code

Our architect talked about using SOA methods throughout our code base, even on interfaces that are not actually hosted as a service. One of his requests is that we develop our interface methods so that we do not make any assumptions about the actual implementation. Therefore, if we have a method that accepts an object and needs to update the property for this object, we obviously need to return the object from the method. Otherwise, we will rely on Something to be a reference type, and C # allows us to update properties by default reference type.

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 understand the benefits of this approach and wondered if anyone could help?

Is this a general approach?

+6
design oop soa
source share
1 answer

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

What you need to do is get acquainted with functional programming and prepare for your conversations about similar cases with your architect. Remember that his intentions are most likely good, but YOUR domain is specific cases. In this case, a side effect is a period, and you most likely want the return type bool to indicate success, but returning a new type does not make sense.

Show your architect that you understand the limited side effects, but certain side effects must be allowed (database, user interface, network access, etc.) and you will most likely find that he or she agrees with you . Find a way to isolate your desired side effects and let them understand him or her, and this will help your cause. Your architect will probably appreciate it if you do it in a collaborative way (without trying to make holes in your plan).

A couple of resources for FP:

Good luck, hope this helps.

+1
source share

All Articles