[fpc-pascal] multiple inheritence
dmitry boyarintsev
skalogryz.lists at gmail.com
Sat Oct 3 10:54:47 CEST 2009
On Sat, Oct 3, 2009 at 7:24 AM, David Emerson <dle3ab at angelbase.com> wrote:
> I'd like to create a "double-list" type, which maintains two parallel
> lists containing the same elements: one sorted, one unsorted. The
> reason to have both: sorted -> fast search; unsorted -> sequential
> navigation through the list while elements are being added.
It can be achieved without need of multiple inheritance.
In your sample t_double_list should also inherit from t_sorted_list,
rather than a t_unsorted_list or t_sorted_list.
t_double_list, can be implemented in the following way.
As you can see, t_double_list even more flexible, than t_double_list
with multiple-inheritance, because actual types of list1 and list2 can
be controlled. For example, if you need to use list1 with sorting A,
and list2 with sorting B... etc.
t_double_list = class (t_list_frame)
private
flist1 : t_list_frame;
flist2 : t_list_frame;
function internal_add (const class_in : class_type) : boolean;
end;
....
constructor t_double_list.create;
begin
flist1 := t_sorted_list.create; // any type of list can be used here
flist2 := t_unsorted_list.create;
end;
function t_double_list.internal_add (const class_in : class_type) : boolean;
begin
flist1.add(class);
flist2.add(class);
Result := true;
end;
thanks,
dmitry
More information about the fpc-pascal
mailing list