uml - OO design: should collections always be stored? -


i've wondered in many different situations, here come, looking experts knowledge. let's have model requires collection. simple example: application stores famous quotes along author , set of tags or keywords. user should able enter tag or keyword , matching quotes it. question is: need class contains collection of quotes? this: example 1

or correct?

example 2

i'm asking in more abstract way possible (after all, uml should never depend on implementation). i've thought second example (just 1 class) incorrect, i'm thinking maybe user can press button on interface , button executes code gets quote stored somewhere, , second example correct?

basically, should have collection stored somewhere, if storing class nothing else store collection (and provide methods access it)?

i definitelly prefer 1 class, if there no strong reason have container class (especially on abstract conceptual level). add collection methods static functions. separate container class bring more complexity, more dependencies , doubts yours. :) doubts indicate lack of real need. when need something, know it.

here example explanations. find simple, clear, elegant , abstract, meaning non-restrictive, easy transform implementation like:

enter image description here

when comes relationships of class other class, actially have collection, without introducing new class. diagram shows 2 examples. "other class" sees collection "quotes" ordered, vector. "one more class" has collection of quotes different characteristics.

later on implementation level can implement directly or adding factory or container class, according concrete, implemention resctrictions , special reqs.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -