Modular Design

lego-bricks

Learning Objectives


When working on larger projects, you will need to carefully plan ahead the structure of your applications/programs. You will have to break down your application into smaller modules and will most likely want to give your end-users the option to navigate through all these sub-modules.

This top-down/modular approach to designing and structuring your applications will enable you to break down what may seem like a very complex project into smaller, achievable modules that you will complete progressively one at a time.

In order for your end-user to access to all the modules available you may be willing to offer a menu structure. This could use drop down menu bars, touch screen icons/menus or a text-based menu system used with a command prompt to interact with the end-user.

In this challenge we will focus on this latest approach: a text-based menu system with a command prompt to retrieve user inputs/choices. Note that the logic behind this would be similar with other types of menus based on a Graphical User Interface or touchscreen or even with a voice activated interface.

Context


We are about to create our first video game and have produced the following top/down modular design for it.
Main-Menu

Let’s look at how this would look like once implemented using Python:

Option #1:


Option #2:


This option is a bit more complex and enables the end-user to navigate between menus and sub-menus.

Option #3:


This code is exactly the same as the code used for option #2. However by splitting the code into mutilple .py files it looks neater and easier to maintain.

When using a modular approach to breaking down a large project we often spread the code accross multiple files. It makes troubleshooting a lot easier.

Improvements


There are many ways we could improve this menu system such as:

  • Add validation methods to make sure the user only enters the right type of menu options,
  • Add a Graphical User Interface to make this menu more visual. To do so we could use a Python library such as PyGame or TkInter.

Did you like this challenge?

Click on a star to rate it!

Average rating 4.5 / 5. Vote count: 2

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!