• 15 hours
  • Easy

Free online content available in this course.

course.header.alt.is_video

course.header.alt.is_certifying

Got it!

Last updated on 3/28/24

Design your system to clarify your needs

 Now that you know why it's important to create a design ahead of time, let's actually create one for a to-do list application.  We'll get the planning done in this chapter, then implement it the next one!

To get started, you have to think about two things:

  1. How to design the model for our software object so that it corresponds to what you want. 

  2. How to design the logic workflow for your specific application.

Let's get started with the first one!

Design the model for your to-do list object

Conceptually, a to-do list is a simple set of ordered tasks that need to be completed. It looks a little something like this:

A Todo-List
A to-do list

You can write a to-do list for all sorts of reasons. Maybe in the form of a grocery list or errands you have to run, or perhaps for prepping your vacation or a new morning routine.  We can extract common elements from all of these different uses of a to-do list (use cases).  In other words, no matter what you use it for, a generic to-do list will allow you to do the following: 

  • Add a task to the list

  • Remove a task

  • Modify a task

  • Visualize the set of tasks

These basic use cases can be incorporated into conceptual design. Sound familiar?  That's right, you can come up with and design a to-do list as a class! This means that it'll need to be able to perform those use cases as operations whenever you need them, regardless of the context.  As you saw in the previous part, a class is actually defined by:

  1. Its state:  This is what we know about the object. It consists of a set of attributes, or simply put, the variables that make up the class.

  2. Its behavior: This is what it can do. It consists of a set of methods.

Let's model out the states and behaviors we need for your to-do list class!

Define the attributes

As you know, a to-do list can be applied to lots of different contexts, so you'll probably want to make sure you have a topic name.  Since a name is going to use letters or characters, you should define its type as a string.

Next, you're also going to need a task or two...or more!  Each task will likely be a short text description, so that means using strings!  You're not going to create a whole application and only allow it to store one task, are you? You could, but let's be a little bit more ambitious. 💪Let's make sure that you can store a bunch of tasks.  In that case, your variable will need a data type that can group lots of separate strings.

Now, you could start off with an array, but you don't know how many tasks you'll need. You need something a little more dynamic and able to order the elements…sound familiar? If you're thinking of an ArrayList, we are on the same page! Let's use a List of character strings as an attribute for the to-do list. 

Try it out for yourself!

Now that you have a rough idea of what you need, try planning out the fields (attributes) for the class on your own!  You can sketch this out with a pen and paper or even map it out on the computer if you prefer. Once you've thought about it, scroll down past the image and see how closely your version matches the one below.

Try it out for yourself!
Try it out for yourself!

Ready for a possible solution?  Yours may look a bit different, but you should have something like this:

Attributes for our class
Attributes for your class

Define the methods

Ok, you've got an idea of the attributes needed in your class. Now, let's discuss the methods that are able to use those attributes.  We talked about some actions you needed to perform with your standard to-do list - now, what would be some good names for those methods?

Try it out for yourself!

Think through exactly which methods you need for your class.  Add the names to your existing diagram, then scroll down to see a solution.

Work out a solution!
Work out a solution!

We defined four actions earlier in the chapter, which you can turn into methods.  Your names might be slightly different, but they should have the same gist:

Methods for our class
Methods for your class

At this point, we have modeled a to-do list conceptually at the class level.  Nice! 😎

Design the logic workflow

Now, for your application, think of a specific use case to apply it to, so that you can make sure to design a proper logic workflow.  Let's go with a checklist for your morning routine. Imagine you've got a new resolution to wake up early and maximize your day. Maybe you want to use your mornings to meditate, read the news, write morning pages, exercise, eat a healthy breakfast, and so on.

Breakfast of champions!
Breakfast of champions!

To make sure you're going to implement the to-do list properly, think of what you need to do, then how you're going to implement it. For example, to get started, you'll first need to create a list.  That's the what. How do you create a list in programming? Well, you'll have to instantiate an object from the class. Do you see where I'm going here?  

From there, you'll need to add elements to the list - what you're planning on doing- and display the list.  If you change your mind and decide you want to read articles instead of cooking breakfast, you'll have to delete a task, then replace it.  Then you'll need to make sure that the list is displaying your new, improved version of the list.  This gives you a pretty good idea of the sequence in which you'd do things as a user:

  1. Create the list

  2. Add the tasks

  3. Display the list 

  4. Change your mind and delete a task

  5. Replace the old task with a new one

  6. Display the full list

For each one of these situations, you can plan the implementation.

Try it out for yourself

Before you look at the example implementation below, try puzzling out how you would integrate each step. Again, use pen and paper or a computer - whatever suits you best! 

Have a go!
Have a go!

Here's a possible way of planning out the implementation:

A plan of what we want to implement and how
A plan of what you want to implement and how

This is a very simple plan, but it gets the initial job done!  Now that you've got a basic plan, you can get coding.

Summary

  • When you want to write a program, think about of all the capabilities you will need. This includes key operations and the data structures necessary to support them. 

  • Define the logic flowchart. This will include the sequence of actions your program will perform.

Ever considered an OpenClassrooms diploma?
  • Up to 100% of your training program funded
  • Flexible start date
  • Career-focused projects
  • Individual mentoring
Find the training program and funding option that suits you best
Example of certificate of achievement
Example of certificate of achievement