Reputation: 174
I am working on a set of classes to represent an Asset Register in Entity Framework. For the sake of keeping the question simple, I have built three classes:
Asset
Contains fields which are applicable to all asset types, e.g. Asset ID, Serial Number, Purchase Date
Computer
Derives from Asset, adds on fields specific to Computer assets, e.g. MAC Address, Hostname
Monitor
Derives from asset, adds on fields specific to Monitor assets, e.g. Size
In pure C# I can instantiate these classes by calling, for example:
Computer DansComputer = new Computer(){ AssetID=12345, SerialNumber="12345", Hostname="DanComputer"};
The UI that I am using to capture new assets requires that the user enter base data about their new asset (from the Asset) class and then discriminate to say, for example, they are creating a Computer asset. I'm wondering if this is less than elegant... In it's current form, the pseudo-code to perform an Insert, regardless of the type of asset would be:
I don't like the commit between views there.
Would a "valid" approach to be one whereby the user selects the type of Asset they wish to add (e.g. Computer, Printer) and then a view to create a new Computer/Printer is displayed? This solution sounds less than ideal to me, because:
I can't, however, think of any other way to make this UI.
Am I missing something really obvious here?
Upvotes: 2
Views: 259
Reputation: 19828
I think the easiest way is to change your steps:
Upvotes: 1