Domain models and Metro (was: First discussion - api/implpattern)
David Leangen
dleangen at canada.com
Tue Oct 5 08:41:12 EDT 2004
> It is very hard to speak in generality. Is like; "I am starting
> an App now, how many classes do I need, roughly?"
I agree.
So let's use a simple concrete example that can illustrate what I'm unsure
about.
Consider a data model oft used for illustration: a Customer class. A first
approach would be like this:
public interface Customer
{
String getName();
void setName(String name);
int getAge();
setAge(int age);
}
public class CustomerImpl implements Customer
{
// implementation of Customer interface
}
First thing... generally the Metro interfaces appear to have only "getters".
In other words, the "setters" would be for configuration, and this is not
included in the interface. So, should I do this?
public interface Customer
{
String getName();
int getAge();
}
public interface CustomerConfig implements Customer
{
void setName(String name);
void setAge(int age);
}
public class CustomerImpl implements CustomerConfig
{
// implementation
}
In any case, the real thing that's unclear to me and the important issue
here is this...
If we're not using a service container--I agree that it would be overkill
for this Customer class--how do we concretely separate the api from the
impl?
If were a "user" of this system and I had some class where I wanted to use a
Customer object, I see no choice but to do something like this:
public class CustomerAccount
{
Customer customer = new CustomerImpl();
// implementation
}
This is exactly the problem! I'm directly using the implementation class
here, when this should somehow be provided to me. Even using a factory I
will have to use it directly from the implementation.
How, concretely, should one go about obtaining the proper implementation
class NOT using any framework like Metro or PicoContainer?
My guess is that I could use a class provider like:
Customer customer = ClassProvider.getClass(Customer.class);
The class provider could call a class loader that looks for "Customer" +
"Impl". Or is this getting into something way over my head?
Dave
More information about the support-dpml
mailing list