Reputation: 491
I have (many more than, but restricting focus to) two class libraries for the model, and another library for view models.
One of the libraries is named Condenser, and has a class called WaterCooledCondenser, which inherits from the HeatExchanger class in the Subcomponents project. The condenser is business logic, but it was designed for the view model to interact with (it is part of the Model). When I create a new Condenser in the view model it says that HeatExchanger is not referenced, and to add a reference to Subcomponents... I don't think the view model has any business knowing anything about the classes in that library, they are only meant to provide structure to the Model.
Would adding a reference to the class library violate MVVM? Is there another way around having the view model know anything about the structure of the model?
Upvotes: 0
Views: 33
Reputation: 590
If these are third party libraries, you may be out of luck. But in general, I would say that your ViewModel should only know how to interact with Interfaces of another library. This way if the library changes implementation it should not beak if the interfaces are the same.
This being said, knowing the basic structure of the model is allowed in MVVM. However keeping the Business Logic and Models completely separate becomes harder when you know the specifics of your class. In order to prevent this interfaces are great tools in future proofing your code.
I would take what I say with a grain of salt; this is completely based on my experience in working within this design pattern.
Upvotes: 1