top | item 46040556

(no title)

jolt42 | 3 months ago

My OO projects were usually in Java with a DB. They all ran afoul of what Martin Fowler calls the Anemic Domain Model. Basically your objects are data-only, so there's no benefit. In addition Spring injection became ubiquitous, and further killed objects with behavior. The only project using a DB and had objects with behavior was an old one that happened to use TopLink as an OR mapping.

discuss

order

ejflick|3 months ago

> Basically your objects are data-only, so there's no benefit.

This makes me wonder why most of us use Java at all. In your typical web app project, classes just feel like either:

1) Data structures. This I suspect is a result of ORM's not really being ORM's but actually "Structural Relational Mappers".

- or -

2) Namespaces to dump functions. These are your run-of-the-mill "utils" classes or "service" classes, etc.

The more I work in Java, the more I feel friction between the language, its identity(OO beginning to incorporate functional ideas), and how people write in it.

marcosdumay|3 months ago

> why most of us use Java at all

Java was the first popular language to push static analysis for correctness. It was the "if it compiles, it runs" language of its day, what meant that managers could hire a couple of bad developers by mistake and it wouldn't destroy the entire team's productivity.

I'm not sure that position lasted for even 5 years. But it had a very unique and relevant value proposition at the time.

elric|3 months ago

A lot of that is down to how people rely on frameworks that force them into "convenient" abstractions. Like Spring and Hibernate. But those are not the language. They represent a (vocal) subset of programmers.

You don't need an ORM or an overgrown dependency injection framework to create a webapp in Java.

vips7L|3 months ago

Service classes are the thing I hate most. They’re just namespaces for functions. They’re a product of Java not being able to have top level functions.

morshu9001|3 months ago

Java is a waste of time for the reasons you said. People use it for legacy reasons. Back then, the alternatives like JS just weren't there yet in several spaces like backend. Your alternatives were even more cumbersome like C++.

fmjrey|3 months ago

OO fatigue is a healthy symptom of readiness to move to clojure, where data and functions are free to live without encapsulation. No king of nouns, no king of execution!

elric|3 months ago

Why did you create an anemic domain model?

Java has had "data carriers" in the form of records for a while now. Immutable(ish), low boilerblate, convenient.

    record User(String name){}
Records are great when doing more "data oriented programming".

vips7L|3 months ago

I don't think anyone sets out to make an anemic domain model, it just happens. Lots of developers start with POJO's for JPA models and then never advance them into being full fledged objects when the requirements develop.

morshu9001|3 months ago

That's not object oriented though