DEV Community

Cover image for Coca Zero, Object Zero, POXO!
medunes
medunes

Posted on

Coca Zero, Object Zero, POXO!

"Object Zero" (~ Coke Zero) is the trend nowadays, yet, Einar Landre warns us that combining logic and state changes in the same class isn't bad, but rather the standard. He literally wrote:

the objects are plain and simple, but not dumb

Objects can change their own states (and should be able to). Foreign classes must communicate through those methods, after all, they constitute its actual interface. This is what Martin Fowler defends in his Tell don't ask principle

Image description

  • IMHO, couple arguments might oppose this principle:

    • Rigidity and tight coupling violating the Open/Closed principle
    • Fragility if deep inheritance comes into play
    • Harder unit test developer experience
    • ORM issues due to eventual "unexpected internal state changes"
    • Eventual concurrency challenges, also due to internal state change.
  • A possible compromise, would be the following: keep using dumb struct like "POXO" objects, yet, implement encapsulated "services" which know how to validate, mutate and utilize those simple objects the right way.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs