I've been working a lot with PHP. But recently i was sent on a work wich use Java. In PHP i used to do a lot of Singleton object but this pattern has not the same signification in Java that it has in PHP. So i wanted to go for an utility class (a class with static method) but my chief doesn't like this kind of classes and ask me to go for services object. So my guess was that a service object is just a class with a constructor that implement some public methods... Am i right ?
+3
A:
Domain-Driven Design defines a Service as:
A SERVICE is an operation offered as an interface that stands alone in the model, without encapsulating state... [p. 105]
Yes, it's a class with public methods, but in addition to that, it implements an interface that exposes those methods. At its core, the Service is the interface - the class that implements it is just an implementation detail.
Mark Seemann
2010-05-28 11:26:53
So if i get it right, for every Utility class that i'm transforming into service i'm supposed to create an interface ?
Maskime
2010-05-28 11:38:40
Yes, well, but in OO, the entire concept of a Utility class is a code smell. True OO classes have well-defined responsibilities...
Mark Seemann
2010-05-28 12:02:53
okay thanks a lot :)
Maskime
2010-05-28 12:05:22