wcf best design principles
Asked Answered
M

1

1

I am looking to make some changes to an existing WCF service. I wanted to know if it would be best to make super methods such as a Save() that would use the values received to decide what action to take or if I should break the actions out into their own methods and expose those for the consumer to decide when to call them.

For instance, I have a payment handler that receives notifications from our merchant when they make a payment attempt and its results. Would it be better for me to allow the handler to pass in the object with a status change and let the super method attempt to figure out what to do with it (assuming no bugs have messed the data up) or create a separate method to extend so the intention is clearly defined.

Note that the super method is also responsible for saving data and changing status along other steps in the process.

I have googled around but haven't really found anything specific. To me the super method violates SOLID but I was told WCF has a different set of standards and its best to make super methods so the consumers don't have to think.

Any feed back is welcome :)

Morra answered 4/10, 2013 at 3:15 Comment(3)
Regardless of SOLID and "WCF standards", you should think long and hard about making changes to an existing service API that forces changes on clients.Griffe
I'm always in favor of focused methods that make it clear what the intent is. Those "super-methods" that can do everything tend to get very hard to understand, extremely hard to maintain, and very error-prone. One method should to one thing and no more - and it should be as clear as possible from the method name and its parameters as to what it does.Hereabout
@PrestonGuillot, I agree, though luckily it is not external facing at this moment but eventually will be. [marc_s], That's what makes sense to me, the current super method setup is hard to follow and understand. We are having bug after bug currently and without defined methods its really hard to tell intention when bad data is being passed around. I figured maybe I am missing something and wanted to see if anyone could justify a super method because I am having a hard time doing so, ever.Morra
T
2

I find that it's best if service operations can exist at a level where they have business meaning.

What this means is that if a business person was told the operation name, they would understand roughly what calling that operation would do, and could make a guess at what data it would require to be passed to it.

For this to happen your operations should fulfill in full or in part some business process.

For example, the following operation signatures have business meaning:

void SolicitQuote(int brokerId, int userId, DateTime quoteRequiredBy);

int BindPolicyDocument(byte[] document, SomeType documentMetadata);

Guid BeginOnboardEmployee(string employeeName, DateTime employeeDateOfBirth);

If you use this principal when thinking about service composition then the benefit is that you will rarely stray far from the optimal path; you know what each operation does and you know when an operation is no longer needed.

An additional benefit is that because business processes change fairly rarely you will not need to change your service contracts as much.

Tabor answered 4/10, 2013 at 7:9 Comment(1)
Great answer! That actually clearly explains the intentions I was looking for. Thanks for the great answer! :)Morra

© 2022 - 2024 — McMap. All rights reserved.