So lets say we are creating a simple “modular system” framework.
The bare bones might be the user management. But we want things like the Page Manager, the Blog, the Image Gallery to all be “optional” components.
So a developer could install the Page Manager to allow their client to add a static home page and about page with content they can easily edit with a wysiwyg editor.
The developer could then also install the Blog component to allow the client to add blog entries.
The developer could then also install the Gallery component to allow the client to show off a bunch of images.
The thing is, all these components are designed to be independent, so how do we go about ensuring they don’t clash? E.g. ensuring the client doesn’t create a /gallery page with the Page Manager and then wonder why the gallery stopped working, or the same issue with the Blog component, assuming we allow the users to customize the URL structure of the blog (because remember, the Page Manager doesn’t necessarily have to be there, so we might not wan’t our blog posts to be Date/Title formatted), likewise our clients aren’t always going to be happy to have their pages under pages/title formatting.
My core question here is, when building a modular system how to we ensure that the modules don’t conflict without restricting functionality?
Do we just leave it up to the clients/developer using the modules to ensure they get setup in a way that does not conflict?
namespaces are the usual response to this. A namespace limits the scope of the components internals (objects, methods and variables).
Different languages implement namespaces to a greater or lesser extent
php:
http://www.sitepoint.com/php-53-namespaces-basics/
javascript:
http://www.kenneth-truyers.net/2013/04/27/javascript-namespaces-and-modules/
Usually you can specify which component you mean by specifying the namespace, e.g.
mycomponents.mylistcomponent specifies the mylistcomponent in mycomponents namespace. Most languages provide a way of skipping specifying the namespace all the time e.g.
in c#:
using System.Objects
will look in the System.Objects namespace for any objects you declare
3
You can’t have both without restricting your user:
allowing users to create the URLs freely AND having collision-free URLs for each module.
If you want to allow users to create URLs, you may check if the entered URL is already in use through doing self-queries but that would still result in having the user restructure the URL catalogue in case there has been a misconfiguration (like in your /gallery
example).
You could create URLs based on module name automatically i.e. /gallery-one
for an entry one
for module gallery
and then offer user functionality to add non-colliding URL rewrites but this may lead to seriously confusing .htaccess files.
1