1. Home
  2. Computing & Technology
  3. Delphi Programming

Programmer Defined Classes and Objects - Delphi OOP Part 3 / Chapter 7
Homework Problems

By , About.com Guide

Because these changes are encapsulated within the TItem and TItemBox classes, the user interface of example 3.3 needs no alteration to interact with this unit as you will see when you run it.

Notice that AddItem without parameters is declared as public (line 10 above) and so can be called directly by the user interface class (eg example 3.2 step 2 line 31). However AddItem with the parameter is declared as protected and so cannot be called by the user interface object. To see this, change example 3.3 step 2 line 49 to call AddItem:

procedure TfrmCount.btnBoxClick(Sender: TObject) ;
begin
  // out of scope
  ItemCount.AddItem(4) ;
end;
This leads to a compilation error.

In Delphi the visibility specifiers private and protected apply to the unit. So in this case we can replace protected by private and the program will still work. However, if these two classes are defined in separate units the overloaded procedure AddItem (aNoToAdd) won’t be accessible with private visibility and so must be protected. (We don’t make it public because we want its visibility to be restricted to TItem and its descendants.)

Chapter summary

  • Keeping user interface and application objects separate: separation of concerns
  • Mimicking RAD user interface objects in programmer defined application classes
  • Steps in using a programmer defined object:
    • define the class,
    • allocate a name (reference),
    • instantiate the object,
    • assign it to the name.
  • Inheritance: deriving a new class from an existing one
  • Packaging a class in a unit
  • The Code Explorer and Project Browser
  • Layout of objects in memory (available in the PDF for download)
Main points:
  1. Defining and using a class and a subclass
  2. Reference semantics and object layout in memory
  3. Separation of concerns: user interface and domain classes

Problems

Problem 3.1 Study Chapters 6 and 7 Part 3
Identify the appropriate example(s) or section(s) of the chapter to illustrate each comment made in the summary above.

Problem 3.2 Double conveyor belts
Extend example 3.3 to work for a double conveyor belt system. One conveyor moves single items and boxes of six items, while the other moves single items only. Clicking down the Display button shows the totals for each conveyor, while releasing the button hides both totals.

Problem 3.3 Different box sizes
Consider another variation on the conveyor belt problem we have been looking at. In a warehouse there is a temporary storage area with three reversible conveyor belts. One carries individual items, the second carries small boxes of four items, and the third carries large boxes with twelve items.

That's it for the third part of the Delphi OOP online tutorial.

Download Part 3, Chapters 6-7 as a PDF document.

Download Ful Source Code.

Download Solution to Homework Problems.

Forward to Part 4 / Chapter 8: Introduction to class inheritance...

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. OOP in Delphi
  6. Free Online OOP Course
  7. Programmer Defined Classes and Objects - Delphi OOP Part 3 / Chapter 7

©2009 About.com, a part of The New York Times Company.

All rights reserved.