Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am writting a small webapp for learning.

Is it better / best practice to create multiple models or one model with multiple custom data types? For example:

Let's say the web app is "PublicLibrary." The library would have shelves. Shelves would have books and locations. Books would have titles, authors, text and a dewey decimal number.

Would it be better to have a Book model, a shelf model (couldn't come up with a better example for this), and a Library model; or a book class, a shelf class, and a Library model that holds those classes. I understand that a model is a class, but hopefully my question makes sense.

share|improve this question

1 Answer 1

You should create classes for every object type that does not have a built-in type.

For example, a Library would contain Books, but a Book would likely use a built-in string type for the dewey decimal number (use a string because you are not performing math on it) and title. Author could be a string, but would likely be reused on multiple books and may have further properties so should stand alone as its own object.

We can provide better guidance if you could post a diagram showing your design along with specific questions regarding how to achieve your goal with the design.

share|improve this answer
    
I think that pretty much answers, and it was what I thought... My only other additional question would be if this library could contain eBooks and the text was now "movie_file." Would you make a Model for 'media' or just book, or book AND ebook? –  Jeff Apr 25 at 14:42
1  
I would have separate entities for media types, but a common interface. Their identity is different: one is a book, one is audio. But they can both be checked out or returned, for example. –  Snowman Apr 25 at 14:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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