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

  • Home
  • SEARCH
  • 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 8719411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:47:31+00:00 2026-06-13T06:47:31+00:00

An application I am writing has groups of users, let’s call them communities. Each

  • 0

An application I am writing has groups of users, let’s call them communities. Each community has meetings which also have a number objects associated with them (attendees, objectives, tasks, accomplishments, etc).

I’m a little confused as to what is the best way to implement initializing the children objects when a parent is created. Here is a simplified class setup.

First Implementation

<?php
class community
{
     public $id;
     public $name;
     //Store an array of meeting objects
     public $meetings = array();
     //Store an array of member objects
     public $members  = array();
     //etc

     public function getProperties()
     {
         //hit database for community properties including ids of meetings 
         //and members associated with this community
         //Set community properties

         //Use returned ids to populate community properties
         foreach($returnedMeetingIds as $meetingId)
         {
              //The meeting class is responsible for its own init.
              $newMeeting = new Meeting();
              $newMeeting->id = $meetingId;
              $newMeeting->getProperties();
              $this->meetings[$meetingId] = $newMeeting;
         } 
     }
}
?>

This method puts the responsibility of initialization on each object which in my opinion is better for maintainability and modularity but I can see this being a huge cascading bottleneck as more meetings are added because each meeting’s child objects would also be responsible for initializing themselves.

The other way I can think to do this is to populate the $meetings array with a single database call. All meetings are stored in a single table with a community id field.

Second Implementation

<?php
class community
{
     public $id;
     public $name;
     //Store an array of meeting objects
     public $meetings = array();
     //Store an array of member objects
     public $members  = array();
     //etc

     public function getProperties()
     {
         $sql = 'SELECT * 
                 FROM meetings
                 WHERE community_id = :community'
         //etc
         $stmt->execute();
         while($meeting = $stmt->fetch())
         {
              $newMeeting = new Meeting();
              $newMeeting->id = $meeting['id'];
              //etc
              $this->meetings[$newMeeting->id] = $newMeeting;
         }

     }
}
?>

I believe the second class will execute much faster but I’ve now coupled the meeting class to the community class and that feels like it isn’t the best of solutions.

My question is how much stock should be placed in decoupling these groups of classes (community, meetings, objective, accomplishment, task, etc)? My own personal feeling is that I should go with the First Implementation until it proves to be inappropriate for my traffic load and then move to something like Second Implementation. I’d like to know what someone with a little more experience has found to be the best practice. I feel this is a rabbit hole that once I go down could be difficult to refactor later. Also I’m not convinced that Either method is the right way to approach this. Thank you so much for any help provided!

  • 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-06-13T06:47:32+00:00Added an answer on June 13, 2026 at 6:47 am

    You have to ask yourself if you really require all those meetings in the community. Let’s take a look at the following use case.

    1. You would like to output all the information of a community including a list of meetings. This may seem like a valid case where you want to construct a community and all its meetings. But there is a more efficient way to this.

      class Controller {
      
          public function showCommunity($id) {
              $community = $this->communityGateway->findCommunity($id);
              $meetings = $this->meetingGateway->findMeetings($community->getCommunityId());
      
              // output your community information and meeting information
          }
      }
      
    2. You have a use case where you need to manipulate all the meetings of a community. In your approach you would do it like this:

      $community = new Community();
      $community->doSomethingToAllMeetings();
      

      But you could just as well use the approach from example #1 for this. Instead of outputting your perform the actions required for the manipulation.


    However if you do require the meetings then you should create them outside the community and pass them into the community object as a dependency (either in the controller if required during creation, or as a setter if they may be added later).

    class Community {
    
        public function __construct($meetings) {
        ...
        }
    }
    

    What do you gain from the above approach?

    • You don’t always load all the meeting information for each community.
    • You decouple the classes. One can now exist without the other and can be replaced for testing.
    • You don’t overburden your business logic with the creation of objects. That should happen at Controller level and not in your business objects.
    • You can even replace those gateways and load your data from somewhere else if you want that.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application which has a JLayeredPane (call it layers) containing two
I am writing an application which has an authenticity mechanism, using HMAC-sha1, plus a
I am writing a server application which has a large amount of source code.
We're currently writing an application for which IT has already purchased hardware for. Their
I am writing an application which has ca. 7000 european restaurants in the database
I'm writing an application. It has a Service which is started using a receiver
The application I am writing coded UI tests for has a window where part
I am currently writing an application where the user has, at some point, to
I am writing an application in JavaScript (with JQuery). The application has a lot
Im writing a WPF application that has a zoom and pan ability, but what

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.