I would like to make my programs much less of a hassle to extend or create, I am imagining a scenario where the end user has a variety of check box options that affect how the program interacts. Something like in a word processor where you say underline, or bold, or to a game where you say, include this feature exclude that one. Just options in general.

How does one create dynamic options that modify the programs behavior without making the program dependent on that feature should one decide to remove that option completely? And what is this type of programming called?

Does one use global variables, (despite some languages suggesting otherwise)

I guess maybe an alternative (metaphorical) way to form this question would be: How do I make my code look more like lego blocks and less like one of those wooden three dimensional puzzles?

Example you can use: Deck of cards, options to remove all the jacks, or all the kings.

  • 2
    beware of over modularization it makes dependency analysis a nightmare and in some environments impossible – user7519 Dec 5 '11 at 18:59

It's called a plugin/hook architecture. It's very common for content management systems, bug trackers, and version control software. Basically, instead of making direct dependencies, you let plugins register callbacks that get called at certain points, called hooks.

For example, a lot of source control software lets you register pre-commit hooks. Whenever someone is about to make a commit, the source control software calls all the registered callbacks for the pre-commit hook. It passes things like the commit message as arguments. If any of the callback functions return false, it won't allow the commit. This lets a customer write a plugin that requires certain information in the commit message without having to change the core software.

  • 1
    This kind of behaviour makes good use of Dependency Injection, the Functional Programming paradigm, and/or the Strategy Pattern – Clockwork-Muse Dec 5 '11 at 22:35
  • I have a lot of studying to do... Trying to find a balance as well as understanding the consequences and how to deal with them. – Mallow Dec 8 '11 at 21:16
  • Could you provide some recommending reading on these topics? Anything that demonstrates some sample implementations of this architecture would be ideal. – jmlane May 24 '12 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.