Ravi Vyas
Ravi Vyas

Reputation: 12375

Monolithic Methods - Disadvantages

Let's say I am creating a MATH class and need to provide a method to process two numbers. [

Instead of providing the traditional mechanism of have methods for each possible operation I provide a single method eval: float eval(ArgObj); where ArgObj is an object which can hold two numbers and an operator. Thus now with a single method I can do multiple operations.

What are the disadvantages of this design?

Two certain disadvantages are maintenance and documentation as eval get the ability to process more operations.

What are the other disadvantages that I am missing out here?

Update: What I am trying to figure out are negatives of a large monolithic method, the above example is just hypothetical another similar example would be a method like

float doSomething(int basedOn)

where doSomething can do a bunch of operations.

Upvotes: 0

Views: 375

Answers (1)

Joe Ratzer
Joe Ratzer

Reputation: 18569

Reading code should be a pleasurable experience, knowing what a method does should be blatantly obvious.

Would you also like to reduce the English language to 10 words? Of course not...

Learn from well-used and well-loved APIs, and ensure your API is easy to learn, easy to use, and difficult to misuse.

I would suggest doSomething doesn't come close. What happens when you need a different action, do you call the new method doSomething2? Hopefully, you don't see that as a viable option...

Upvotes: 1

Related Questions