Photo by Brett Jordan in Pexels

Problems

  • Mutability
  • Incomplete objects
  • Concurrency inconsistencies between creation and essence setting.
  • Setters

Solutions

  • Pass the object’s essence on creation

Examples

  • Some persistence frameworks in static typed languages require an empty constructor.

Exceptions

  • Stateless objects. Always better solution than static class methods.

Sample Code

Wrong

Right


Your objects are a bunch of public attributes without behavior.

Photo by Stacey Vandergriff on Unsplash

Problems

Solutions

Examples

  • DTOs

Sample Code

Wrong

Right


If your class relies on too many others, it will be coupled and fragile. A long import list is a good indicator.

Photo by Zdeněk Macháček on Unsplash

Problems

  • Coupling
  • Single Responsibility Principle violation
  • Low Cohesion

Solutions

Sample Code

Wrong

Right

Detection

Tags

  • Coupling
  • Ripple Effect

Conclusion

Relations

More Info


Magic functions that can receive a lot of different (and not polymorphic arguments)

Photo by Hennie Stander on Unsplash

Problems

Solutions

Sample Code

Wrong

Right

Detection


If your classes are globals, use fully qualified names

Photo by Edvard Alexander Rølvaag on Unsplash

Problems

  • Readability
  • Mistakes

Solutions

  1. Rename your classes to provide context
  2. Use modules, namespaces or fully qualified names

Sample Code

Wrong

abstract class PerserveranceDirection { 
}
class North extends PerserveranceDirection {}
class East extends PerserveranceDirection {}
class West extends PerserveranceDirection {}
class South extends PerserveranceDirection {}
//Subclasses have short names…


We are big fans of xUnit. But we don’t care much for the programmers.

Photo by Startaê Team on Unsplash

Problems

  • Readability
  • Hard debugging
  • Time waste

Solutions

  1. Put a nice descriptive assertion
  2. Share guides for problem-solving

Sample Code

Wrong

<?public function testNoNewStarsAppeared(): void
{
$expectedStars = $this->historicStarsOnFrame();
$observedStars = $this->starsFromObservation();
//These sentences get a very large collection
$this->assertEquals($expectedStars, $observedStars)…


Photo by Ashim D’Silva on Unsplash

Problems

Solutions

  1. Name the events after “what happened”, not “what you should do”.

Sample Code

Wrong

const Item = ({name, handlePageChange)} =>
<li onClick={handlePageChange}>
{name}
</li>
//handlePageChange is coupled to what you…


One class calculating formulas for another class.

Photo by Michal Matlon on Unsplash

Problems

  • Declaratively
  • Low reuse
  • Real-world concept missing
  • Encapsulation

Solutions

Sample Code

Wrong

Right

Detection

Tags

  • Encapsulation
  • Coupling

Conclusion

Maximiliano Contieri

I’m senior software engineer specialized in declarative designs. S.O.L.I.D. and agile methodologies fan.

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