design - How much responsibility should a method have? -


This is most definitely a language agnostic question and which has troubled me for some time. An example might explain this dilemma that I am facing:

We have to say that we have a method that is responsible for reading the file, some objects (which store information from the file) Makes a collection with it. And then returning the collection ... like something like this:

  public list & lt; SomeObject & gt; Load Synchronization (string filename);  

We should also say that at the time of implementing this method, if the collection was returned then it would be impossible for the application to continue (size of 0). Now, the question is, should this belief (an empty archive should be checked and perhaps to throw an exception) should be done within the method? Or, should this method be allowed to complete the file load and ignore the verification work, to verify at some later levels beyond the method?

The general question I am asked is: Is it better to double the validity of the actual work by a method? In the case of my example above, in general, it will be easy to change or create later phase, this may be a case where in the subsequent situation a separate strategy is attached to recover from the position of the vacant position. Ho is being refunded from the 'Load Configuration' method ... It would be difficult if verification (and consequent exception) was being done in the method.

Perhaps I'm highly pendant for search, some radical answers, instead it simply depends on the context in which a method is being used. Either way, I would be very interested to see what others have to say about it.

Thank you!

My recommendation is to stick to the single responsibility principle which, in essence, is the object of every object In this example, your method has 3 objectives, and then 4 if you calculate the recognition aspect.

Here is my recommendation on how to handle it and how to provide large amounts of flexibility in future updates.

  • Place your load config

  • This is a new method for reading the file.

  • Pass the object collection in some validation method.

  • It is taking 1 method in the beginning and it breaks into 4 and makes 3 other calls

    Hope it helps


    Comments

    Popular posts from this blog

    asp.net - Javascript/DOM Why is does my form not support submit()? -

    sockets - Delphi: TTcpServer, connection reset when reading -

    javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -