Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 884139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:42:26+00:00 2026-05-15T12:42:26+00:00

How to design classes involving collections of other classes? General Example: A Workspace contains

  • 0

How to design classes involving collections of other classes?

General Example:

A Workspace contains number of Projects .
A Project contains large number of Resources .
Each Resource may contain large number of Files.

So here the classes identified can be Workspace,Project,Resource and File.
Workspace will have list of Project.Project will have list of Resources and Resource will have list of Files. Of course each class has its related settings.

Now the basic questions are :
a) Who creates and adds a class to a particular collection? Another class or the class containing the collection?
b) Also how to keep track of a particular collection and how to store same?
c) Who audits changes to a particular collection?
d) What are the different design patterns that could be applied in such situations?

Basically I want to reduce the coupling between the different classes .

Thanks Everyone

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:42:26+00:00Added an answer on May 15, 2026 at 12:42 pm

    There are many kinds of relationships – consider

    • Automobile and Wheels
    • Automobile and Driver
    • Automobile and Registered Owner
    • Customer and Order and Order Line
    • School and Class and instance of Class

    If you look at UML modelling you’ll see concepts such as Cardinality and Direction and distictions between Aggegration and Composition and questions relating to the life-cycle of the related objects.

    It’s then unsurprising that we need a range of techniques and patterns to deal with different kinds of relationships.

    Concerning d). There’s one overriding principle Law of Demeter or principle of least knowledge.

    One important technique is then, Encapsulation decrease coupling by hiding information. Automobiles probably have little interest in many details of people, so we might have a IDriver interface on our Person class, IDriver offers the particular methods that Automobile cares about. The general principle being to favour programming to interfaces.

    Following that through, we can think about a). Creation. As we’re tending to use Interfaces, it often makes sense to use Factory patterns. That does leave the question of who calls the factory. Do we prefer:

       IPerson aPerson = myAutomobile.createDriver( /* params */);  
    

    or

      IPerson aPerson = aPersonFactory.create( /* params */);
      myAutomobile.addDriver(aPerson);
    

    Here I think it’s pretty clear that Automobiles don’t know much about people, and therefore the second is better division of responsibilities. However maybe Orders could reasonably create OrderLines, Classes create ClassInstances?

    b). Keeping track? That’s why we have rich sets of Collection classes. Which ones to use depend upon the nature of the relationship (one-one, one-many; etc.) and how we use it. So we pick Arrays and HashMaps etc. according to need. For a Car/Wheel we might even use names attributes of the Car – after all a Car has exactly six wheels (frontLeft, frontRight, backLeft, backRight, spare and steering). If by “store” you mean persist, then we’re looking at techniques such foreign keys in a relational database. Mapping between RDBMS and in-memory objects is increasingly managed by nice persistence mechanisms such as JPA.

    c). Audit? I’ve not seen auditing applied specifically at a relationship level. Clearly the automobile.addDriver() method may be arbitrarily complex. If there’s a business requirement to audit this action, then it’s pretty clear that this a decent place to do it. This is just a standard OO design question revolving around who owns the information. General principle: “Do Not Repeat Yourself” so pretty clearly we don’t want every object that calls addDriver() to need to remember to audit, hence it’s Auto’s job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The project has a goal: use interface centric design. Basically we declare classes of
In general, I design classes in such a manner as to not require access
I'm looking for inspiration on how to design classes from scratch in a project
I have a couple of classes that want to pass each other some information
I'm developing a multi-timertask project. First of all, I design some classes extended TimerTask
I'm using LINQ to SQL classes in a project where the database design is
I've tried to design some classes to support a callback functionality. Classes MyClass1 and
I have this pimpl design where the implementation classes are polymorphic but the interfaces
This is a design principle question for classes dealing with mathematical/physical equations where the
OO Design question. I want to inherit singleton functionality into different hierarchies of classes.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.