Software Design

From FRC11 - Mentor Wiki
Jump to navigation Jump to search

There are lots of ways to design software, of which we just give an overview of some of the more prominent and readily available techniques.

High Level and Low Level Design

Almost all system design tasks are split into two levels of design - High Level, sometimes known as Architectural Design and Low Level, sometimes referred to as Detailed Design. The following practices fall into one or both of these categories.

Flow Charts

Flow charts are a good way to get started, though once you have a good feel for coding, other techniques often work better.

An example flow chart to fix a lamp An example flow chart to wash hair

Flow charts consists of actions, states, decisions, and paths, and is most appropriate for low level design. Boxes can represent items to perform or states of items in the system. Diamonds represent decisions to make. Arrows may be unlabeled when going to consecutive items, but outflows from a decision must be labelled with the value used in the decision.

To design using flow charting, you have to think sequentially, and in terms of how control is determined - in particular, what decisions are to be made and on what basis.

Why Flow Charts can be good

Flow charts can be useful even to the experienced programmer for smaller items and when trying to get a good feel for the sequence of actions and decisions that need to be made.

Why using Flow Charts can be bad

  • Flow charts have a tendency towards producing spaghetti code
  • Don't represent loops well
  • Don't represent objects well
  • Difficult to use decomposition
  • Unwieldy for large or complex items
  • Easier to design in pseudo code or using other techniques

Data Flow Diagrams

Design using Data Flow Diagrams (DFD) is a simple technique to represent the objects in the system and the flow of information between producers and consumers. It's good for procedural programming to identify and get a feel for how data needs to move about the system, and certainly for object oriented design, especially in conjunction with other methods.

Circles (or bubbles) represent objects or processes in the system. Arrows represent the flow of information between bubbles, and boxes without sides represent data stores, such as files or databases. Flows (the arrows) are always labeled with the data that is being transmitted. You can abstract or group data, if the number of individual data items gets to be too much for the diagram. Then you can list the group names, instead of the individual items on the diagram, and define elsewhere what data items are present.

Data Flow Diagrams are most useful during Architectural Design (High Level design), but can be used a bit even at the lower levels as well.

Decomposition

Decomposition is the most important design technique for complex problems, and is necessary for both High Level and Low Level design activities, and is used in conjunction with Functional Specification.

Complex tasks or objects, and sometimes reasonably simple tasks, must be broken down into smaller, easier to design and implement chunks. Anything that is non-trivial should be broken down. Keep decomposing until it is easy to implement. If a function grows longer than about a page or 60 lines, you should usually decompose it further. You can decompose smaller than that, as well, whenever it makes sense - when you have a cohesive, well defined task.

A complex task can be broken down into simpler steps, or a complex object can be broken down into parts. In turn, the smaller steps may be further broken down.

In trying to determine where best to split a task, there are sometimes natural boundaries where it may be obvious. Feel free to use those. But also try to separate areas that have little communication or interaction between them. Any communication (such as data flows) should be able to be easily defined.

At the Architectural Design level, break down the system so that all of primary functions, capabilities, or objects are defined, and any complex primary objects should be further delineated. At the Detailed Design level, break down the objects and functions until their implementation is nearly trivial.

When breaking down an item, understand and specify what information the lower level task (or object) needs. Use pseudocode and Functional Specification described below to indicate the needs of the lower level item.

Pseudocode

Pseudocode is a simple, informal way to specify high level or detailed level design information in steps. It is usually a mix of statements that look like English or a little like programming code. You can use whatever is appropriate to the level of design in which you are engaging. By the time you complete your detailed design you should have roughly one line of pseudocode for every 3-10 lines of actual code.

Try to use precise statements when you can, and when precision is useful, but they are not needed all the time.

Hair Washing Example

Repeat the following until hair is clean:

Wash
Rinse

Functional Specification

A Functional Specification is a precise way to define what the system, function, or object is expected to do in a particular circumstance. It does not specify how to perform the operations, but should specify any important criteria about the result. If you need a sorted list of something returned, don't just specify a list, specify a sorted list.

Depending a what is being specified, a functional specification can take different forms. But if you are decomposing a system and need to create functional interfaces, you the functional specification must include a function signature (Name, return value and type, arguments and their types), and must also indicate a 1-2 line description of what the function needs to accomplish. This description is called the Intended Function, an indicates what the function is intended to do.

Wash hair example

bool Wash_Hair(shampooName : shampoo_type; shampooVolume : ounces)

Wash and rinse head of hair until clean using shampooVolume amount of shampooName type of shampoo, until clean, and rinse. Return true if successful, false if there was insufficient shampoo left or no hot water.

Object Oriented Design