Reputation: 3747
I began to work on some small project and currently thinking about best approaches in architecture. Assume I have a class with a lot of properties that I retrieve in controller from my database.
Building building = BuildingsBLL.GetBuilding(buildingID);
Buildings are of different types with different sets of properties.
I see two options:
I can pass Bulding
to common view with a lot of code and show /
hide specific blocks on the page according to the building type (using if building type blablabla...). Or
I can cast building to another type (School
or Hospital
or smth
else) and pass it to certain view with minimal amount of code.
So in the first case I need just one view and no models(?) and in the second case I need separate model and view for each building type.
In my opinion the second case is preferable. But maybe I'm missing something and aforementioned approaches are not usable at all?
Upvotes: 1
Views: 632
Reputation: 17182
So in the first case I need just one view and no models(?) and in the second case I need separate model and view for each building type.
I would do it in following way - Have abstract Building
Model, then inherit SchoolBuilding
and HospitalBuilding
models from Building
Model.
Then in the frontend, if I have lot of operations on both School and Hospital buildings, then I will have separate controllers for both. But if operations are considerably less, then I will have only Building Controller in which different actions corresponding to School and Hospital models. Based on the amount of re-usability, I will extract some partial views for both hospital and school actions.
Upvotes: 1