Filtered Iterators

While having a clearly defined method of moving through a collection is helpful, you can also define filtered Iterators that perform some computation on the data before returning it. For example, you could return the data ordered in some particular way or only those objects that match a particular criterion. Then, rather than have a lot of very similar interfaces for these filtered iterators, you simply provide a method that returns each type of enumeration with each one of these enumerations...

Simple Report Example

Let's consider a simplified report generator that can operate on five columns of data in a table and return various reports on these data. Suppose we have the following results from a swimming competition. The five columns are frname, lname, age, club and time. If we consider the complete race results of 51 swimmers, we realize that it might be convenient to sort these results by club, by last name, or by age. Since there are a number of useful reports we could produce from these data in which...

Building the Employee Tree

We start by creating a CEO Employee and then add his subordinates and their subordinates, as follows. prez new Boss CEO, 200000 marketVP new Boss Marketing VP, 100000 salesMgr new Boss Sales Mgr, 50000 advMgr new Boss Advt Mgr, 50000 marketVP.add salesMgr marketVP.add advMgr prodVP new Boss Production VP, 100000 advMgr.add Secy, 20000 add salesmen reporting to sales manager for int i 1 i lt 5 i salesMgr.add Sales i.ToString , rand_sal 30000 prodMgr new Boss Prod Mgr, 40000 shipMgr new Boss Ship...

Garden Maker Factory

Let's consider a practical example where you might want to use the abstract factory in your application. Suppose you are writing a program to plan the layout of gardens. These could be gardens consisting of annuals, vegetables, or perennials. However, no matter which kind of garden you are planning, you want to ask the same questions. 1. What are good border plants 2. What are good center plants 3.What plants do well in partial shade And probably a lot more plant questions that we won't get...

The Vis Rectangle and Vis Circle Classes

We can take some useful advantage of inheritance in designing our visRectangle and visCircle classes. We make visRectangle implement the Drawing interface and then have visCircle inherit from visRectangle. This allows us to reuse the setSelected, setFill, and move methods and the rects properties. In addition, we can split off the drawHandle method and use it in both classes. Our new visRectangle class looks like this. public class VisRectangle Drawing protected int x, y, w, h private const int...

The Boss Class

Class Diagram Salary Employee

Our Boss class is a subclass of Employee and allows us to store subordinate employees as well. We'll store them in an ArrayList called subordinates and return them through an enumeration. Thus, if a particular Boss has temporarily run out of Employees, the enumeration will just be empty. public Boss string name, float salary base name,salary ------ public override void add string nm, float salary AbstractEmployee emp new Employee nm,salary subordinates.Add emp public override void add...