How to use GoF design pattern for software robustness?

74 views Asked by At

Robustness is defined by IEEE as "The degree to which a system or component can function correctly in the presence of invalid inputs or stressful environmental conditions".

What real-world scenarios can illustrate this problem? And what GoF design patterns are suitable for solving robustness?

Since the areas of robustness are error handling, fault tolerance, and recoveryability. But I don't have an idea how to use design patterns to solve it.

class Dao {
   ... 
   public void timeout() {
       // some logic here 
       throw new RunTimeException("This session is timeout");
   }
}

Many exceptions may be defined in the Dao class.

If I use design patterns to solve this problem, should I create a factory pattern to handle each exception and create a class for each exception?

2

There are 2 answers

2
KoalaMaybe On

GoF and design patterns are just a set of solutions that software engineer noticed keep reoccurring.

Many beginners unfortunately try and cram these design patterns into every problem they see, this is a very bad usage of them.

Since the areas of robustness are error handling, fault tolerance, and recoveryability. But I don't have an idea how to use design patterns to solve it.

GoF does not guarantee robustness (or anything really). GoF is just a bunch of really common solutions that four engineers have noticed. Other design patterns (non GoF) too, are just common solutions (but not as widely recognized as GoF's)

0
queeg On

The patterns are not useless, but applying them just for the sake of applying them will overengineer every project.

Knowledge about design patterns allows to better distribute code over classes and interfaces such that it is flexible to use and maintainable.

Robustness means an application can deal with strange input, or with varying conditions such as a partner system that has gone offline. Design patterns do not change the robustness per se.

But if you have well designed code, it is easier to spot the location where error handling needs to be improved. And this indirectly contributes to to more than just robustness.