Professional C__ - Marc Gregoire [22]
emp.promote(raiseAmount);
} catch (const std::exception&) {
cerr << "Unable to promote employee!" << endl;
}
}
Code snippet from EmployeeDB\UserInterface.cpp
Evaluating the Program
The preceding program covers a number of topics from the very simple to the more complex. There are a number of ways that you could extend this program. For example, the user interface does not expose all of the functionality of the Database or Employee classes. You could modify the UI to include those features. You could also change the Database class to remove fired employees from mEmployees.
If there are parts of this program that don’t make sense, consult the preceding sections to review those topics. If something is still unclear, the best way to learn is to play with the code and try things out. For example, if you’re not sure how to use the ternary operator, write a short main() function that tries it out.
SUMMARY
Now that you know the fundamentals of C++, you are ready to become a professional C++ programmer. The following chapters will introduce you to several important design concepts. By covering design at a high-level without getting into too much actual code, you will gain an appreciation for good program design without getting bogged down in the syntax.
When you start getting deeper into the C++ language later in the book, refer to this chapter to brush up on parts of the language you may need to review. Going back to some of the sample code in this chapter may be all you need to see to bring a forgotten concept back to the forefront of your mind.
Chapter 2
Designing Professional C++ Programs
WHAT’S IN THIS CHAPTER
The definition of programming design
The importance of programming design
The aspects of design that are unique to C++
The two fundamental themes for effective C++ design: abstraction and reuse
The different types of code available for reuse
The advantages and disadvantages of code reuse
General strategies and guidelines for reusing code
Open-source libraries
The C++ standard library
The specific components of C++ program design
Before writing a single line of code in your application, you should design your program. What data structures will you use? What classes will you write? This plan is especially important when you program in groups. Imagine sitting down to write a program with no idea what your coworker, who is working on the same program, is planning! In this chapter, we’ll teach you how to use the Professional C++ approach to C++ design.
Despite the importance of design, it is probably the most misunderstood and underused aspect of the software-engineering process. Too often programmers jump into applications without a clear plan: They design as they code. This approach inevitably leads to convoluted and overly complicated designs. It also makes the development, debugging, and maintenance tasks more difficult. Although counterintuitive, investing extra time at the beginning of a project to design it properly actually saves time over the life of the project.
WHAT IS PROGRAMMING DESIGN?
Your program design, or software design, is the specification of the architecture that you will implement to fulfill the functional and performance requirements of the program. Informally, the design is how you plan to write the program. You should generally write your design in the form of a design document. Although every company or project has its own variation of a desired design document format, most design documents share the same general layout, including two main parts:
1. The gross subdivision of the program into subsystems, including interfaces and dependencies between the subsystems, data flow between the subsystems, input and output to and from each subsystem, and general threading model.
2. The details of each subsystem, including subdivision into classes, class hierarchies, data structures, algorithms, specific threading model, and error-handling specifics.
The design documents usually include diagrams and tables showing subsystem interactions and class hierarchies.