
question about decoupling mvc
this question is about how to better decouple a 3 layer architecture based
on iterfaced implementations.
imagine these classes:
class Model {
public String Name;
private IImplementation implementation;
public Model(IImplementation implementation){
this.implementation = implementation;
}
public void Save() {
implementation.Save(this);
}
Quote:
}
public interface IImplementation {
void Save(object obj);
Quote:
}
public class ImpFilesys : IImplementation {
public void Save(object obj) {
// implementation code goes here
}
Quote:
}
public class ImpDataBase : IImplementation { ... }
public class Client {
public Client() {
Model m = new Model;
m.Name = "Don Camillo";
m.Implementation = new ImpFilesys(); // yuck!
m.Save(m);
}
Quote:
}
using this design i could sucessfully decouple the model from it's
implementation. but at the cost to couple implementation to the client,
which i also do not want. how can i achieve that the model only knows model
stuff, while the implementation knows only imp-stuff and same for the
client? how can i make them truly interchangeable without having to change
the code each time?
thanks
jan
(ps sorry for the repeat)