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 7165479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:15:24+00:00 2026-05-28T14:15:24+00:00

I’m trying to figure out if I understand correctly what modular code really is.

  • 0

I’m trying to figure out if I understand correctly what modular code really is. I know that it’s extremely powerful / useful so I want to make sure I’m learning it correctly.

To start learning, I made a fairly simple system that groups Entities together based on some criteria. First come, first serve.

I also want to graphically display the groups and their member’s, to show the user (myself) what’s going on. I’ll use the SDL library for this.

So let’s divide that into some classes;

Entities

The main class “Entities” will have a Boost::mutex for thread safety, and a map holding pointers to actual entities. Let’s also make a function that retrieves a pointer to the actual entity from said map, when provided with the entity ID.

class Entities
{
public:
    boost::mutex access_entitymap; //Thread safety
    std::map<unsigned int, Entity*> entitymap;

    Entity* getEntity(unsigned int entityID);
};

Entity

Holds information about the actual entity, such as it’s uniqueue ID. And a pointer to the parent “Entities”.

LFDGroups

The grouping system.
Includes a map with pointers to the actual groups,
a map with the group’s position in the queue (first come first serve. full groups are removed from this map to make iterating faster),
and a map with an entity’s position in the group (5 spots, which entity has taken which spot?).
Furthermore it also includes some functions to operate on said maps. Such as adding and removing members. The addmember() function will, as an example, make sure the entity is added to the group with the most priority, or that a new group is made if necessary.

groupObject

Holds information about the actual group, such as it’s uniqueue ID and it’s inhabitant entities’ IDs. But also has some functions such as;

LFDGroups *lfdgroup; //Parent LFDGroups;
bool isEmpty(); //is this group empty?
bool isFull(); //is this group full?
unsigned int getPosition(); //Position in queue?
bool addMember(unsigned int entityID,bool snatchIt); 
/*Add a member. Calls removeMember() on the entities' groupObject 
first if the entityID is already in another group.*/
bool removeMember(unsigned int entityID,bool snatchIt); 
/*Remove a member from this group, and snatch a member from another 
group further up in the queue. This ensures groups are always full 
if enough people are queued.*/
bool hasMember(unsigned int entityID); //Is this entity ID in our group?
/*etc. etc.*/

Queue

Provides some ease-of-use functions to make testing easier. Such as;

void addFakeEntity(bool queuenow); //Create an all new entity and immediately queue it.
void removeFakeEntity(); //Remove a random entity from a random group
void removeFakeEntity(unsigned int entityID); //Remove a given entity from it's corresponding group.

SDLMain

Graphically displays what’s going on with LFDGroups’ groups. How many members it has, which spots are taken and which aren’t etc.

Also proves buttons to work with Queue’s functions. Such as the “Add” button will call “queue->addFakeEntity(true)”

So now I can just start the whole thing up easily;

#include "SDL_main.h" //gfx
#include "class_LFDGroups.h" //group system
#include "queue.h" //ease of use for testing
#include "class_entities.h" //entities

int main( int argc, char* args[] )
{
    Entities * entities = new Entities;
    LFDGroups * lfdgroups = new LFDGroups(entities);
    Queue * queue = new Queue(lfdgroups);
    SDLMain * sdlmain = new SDLMain(queue);
    return 1;
}
  1. Entities can be used without anything else.
  2. LFDGroups can be used with nothing but entities.
  3. Queue needs both, but LFDGroups already contains a pointer to
    Entities. After all, it can’t function without it.
  4. SDLMain uses all 3.

And sure enough;

group_example

So this means that even if I do disable the graphically displaying of the groups, I can still use the actual grouping system for other things.
And also, functions relating to certain objects are within that object itself. As an example, the Entity* getEntity(unsigned int entityID); function is in the Entities class and not in groupObject, even though that is the only one that’s using it at the moment.

Is this all that modular coding is? Am I doing it right?

  • 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-28T14:15:24+00:00Added an answer on May 28, 2026 at 2:15 pm

    Yeah your program looks to adhere to modular programming paradigms, such as having separate components that come together to make up the program, and written in a way that particular components could be replaced.

    So you’ve split the logic of the program into separate classes, and you also split the classes into separate compilation units (assuming so, based on the includes in your SDLMain.h source), so to add a new feature to say your group class, would only require changing that module (assuming the new function was only called by internally to that class), and from looking at your source the program is logically split into separate parts that are easily identifiable.

    You also could easily replace part of your code, for example the GUI front end could be replaced with Qt or wxwindows for example. Since the operations the gui calls into the data don’t change, the new gui code can be written, and call the same set of operations, and the data components will not be altered.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.