2

Let us say that I have a Book class, a book can have an object of another class like an Author or other complex objects like a list of Genres. My question is, in an MVVM model should I make the complex object a property or should I use a simple object like Integer which contains a reference to the complex object, like it's ID?

1 Answer 1

1

The Model is much more than a dumb data object. It can (and should) contain references to other objects, hold collections and so on.

In your case, you may have an Author, which has a collection of Book, which may have a collection of Genre. This really depends on your data structure, but you get the idea.

A good example would be Entity Framework, as it follows the pattern of having the foreign key (the ID), and the object itself. See here for more information.

There is nothing wrong with having references to other classes in your model.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.