Step 2

Program quality and ease of use

Objectives
You are now assumed to master the basic object-oriented principles, learned from previous step, meaning that your programs maintain a general basic OO-quality. This means that you are aware of which constructors and member methods are appropriate to provide in your classes, in order to anticipate problems for its (re)users.

After Step 2, you should be familiar with the object-oriented key concept of encapsulation, which is intended to conceal how an object’s behavior and data is actually implemented and how to use appropriate programming techniques to support this. Your program should show a (meaningful) controlled access to the class’s data members, especially using visibility declarations (the keywords private and public), but also by use of get- and set-methods. Use of const declarations of objects and their methods is another important quality assurance for your applications, that you must master.

You should understand the purpose of operator overloading and know how to (moderate and restrictive) define your own operators, in order to make your class flexible and adaptable. This means providing it with member functions, which adapt some common C++ operators to your user-defined type (class). By using the concepts of friend and inline, you will also have knowledge of how to extend (standard) classes with needed functions. Finally, you’ve got to learn how to ensure a stable and fail-safe program execution, using the mechanism for exception handling.

Contents
In step lessons are first treated the technique to define your own operators. Then are introduced some object-oriented quality techniques for safe handling of the class’s data members, in other words, ways to protect the class content and promote good fail safety. The theory, that should be read in mentioned order, is to be found in the course book’s Ch. 13 (Operator Overloading), supplemented with Ch. 11: 264-266 (inline functions), Ch. 12: 274-278 (friend functions) and Ch. 18: 420-425 (Overloading the I/O Operators). The concept of const in particular treated in Ch. 9: 182-184 and Ch. 20: 486-488 (const member functions). Final reading is Ch. 17 (Exception Handling)

Concepts that are covered:

  • Operators – different variants, priorities and possibilities for overloading
  • Operator functions are implemented as member functions
  • Extension of standard classes with common functions
  • inline function, advantages and limitations
  • friend declaration allows external functions to access private data
  • The concept of const
  • Encapsulation of objects
  • Access control with get()- and set()-methods
  • Error handling with the support of exception handling

Welcome to CoursePress

en utav Linnéuniversitets lärplattformar. Som inloggad student kan du kommunicera, hålla koll på dina kurser och mycket mer. Du som är gäst kan nå de flesta kurser och dess innehåll utan att logga in.

Läs mer lärplattformar vid Linnéuniversitetet

Student account

To log in you need a student account at Linnaeus University.

Read more about collecting your account

Log in LNU