I wrote:
procedural = all static methods
OOP = use of interfaces, private fields public methods
It seems as if you are mostly arguing based on:
procedural = some static methods
I don't think the presence of some static methods is anti-OO.
Several patterns from the GoF book uses static methods.
You're pushing me too far over to one side when you characterize my
arguments. So far I've said little about static methods - I've been
noting the misuse of instance methods. I've focused deliberately on
instance methods because it is easier to disguise their misuse.
As far as static methods go, I don't think the use of *some* static
methods is bad either. They are inherently procedural, however. You
acknowledged that to some degree when you equated 'procedural = all
static'. I happen to think that the bar should be lower, that the more
of your code that you've jammed into static methods the more procedural
your code has become. There's no 0/100 black/white here.
I prefer static methods that are non-business-logic implementation
details, if you've got to use them at all. Like static factory methods.
And I do not agree with the service methods plus data classes
not being OOP argument either.
It's OOP. It's _technically_ OOP. More discussion below.
Back in the 90's good OOP was rich classes with both methods
and data.
Not always "good" OOP. Let's just call that "1990's OOP" or "1990's
accepted OOP".
Today good OOP is more focused on the encapsulation aspects
(which was my second bullet point).
The 90's good OOP is now called "rich domain model".
One of the main drivers behind the change IMHO is that it became
clear that not everything was a good fit for traditional model. There
are simply needs for different focus on data versus method: some
classes are method heavy, some classes are a more even mix
and some classes are data heavy.
That's exactly right: it became clear that the "emergent" premise behind
the rich domain model typically failed. People invariably had a
difficult time deciding where to put all their logic, because much of it
did not neatly belong to any one domain class. That led either to
abstract and dubious domain classes for the purpose of holding methods
that had no better home, or drove that change you referred to above (and
which I've criticized): creating lots of service classes in an
application layer, where this difficult-to-place logic gets put as
instance methods.
As a short-term response to the flaws inherent in the rich domain model
I have no serious problems with that change. A great deal of logic _is_
procedural, and you should code it up that way. But let's not call it
OO. My argument is just that, that a lot of Java code is procedural. I'm
not saying it's awful. When I previously used language like "ought to
have been", I'm saying that in reference to what you'd strive for with
classic, rich domain model OO.
This is my point exactly: that this change to lots of procedural, for
basically good reasons, has happened in Java (and other class-oriented
languages like C#). What is a problem is that people continue to insist
that this procedural code isn't.
I've mentioned DCI numerous times before: it is precisely an effort to
put some formalism and structure into how one deals with this
algorithmic/procedural code in an OO environment.
Encapsulation is used in almost all Java EE apps, because
Java EE is designed over these concepts and so are much of
the supplementary stuff like Hibernate (non JPA API),
Spring etc..
Arne
Encapsulation is great. I don't care if one class is basically a struct
(Java Bean) and another is a domain class loaded with behaviour - they
all have their place. Encapsulation enters into all of that.
However, the argument here is about where a lot of the procedural logic
goes. The attempt to keep it all in domain classes failed a long time
ago. People have adjusted, often quite well. What's been missing is a
general acknowledgement that we write a *lot* of procedural Java code,
and maybe work on ways to formalize how to do that well. DCI is one
approach.
AHS