Single Responsibility Principle: Back to basics or over-engineering?

Money class

Creating money

One creating method

  • creating the money object
  • checking the argument type
  • throwing an exception when the argument is not supported

Creating from integer

Creating from string

Two creating methods

  • simpler
  • easy to understand
  • fewer exception states
  • safer — uses types

JSON Serialization

{ "amount": "500.50"}

Internal serialization

External serialization

Price module

  • What is the price of the product?
  • What is the price of the shipping?
  • What is the overall price of the order?

When splitting doesn’t make sense

Single responsibility of a variable

Over-engineering

Conclusion

Contact

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Svaťa Šimara

Svaťa Šimara

Developer interested in Domain-Driven Design & Modeling