473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

OO: Who am I in the hierarchy?

I have an abstract class that is a windows form called "BaseList" that
contains a grid control. This grid control is then populated by any
concrete class that inherits from BaseList. I have a class SpecificList
class that is a kind of BaseList (class SpecificList:BaseList). When a
user interacts with the SpecificList, they will be allowed to save the
layout of that grid. Now, here's the rub.

I want to put the code into BaseList for storing the layout of the grid.
But I need to store the layout uniquely for each instance of BaseList.
In other words if I want to save the layout of SpecificList, the code
executed in BaseList needs to know the name of the concrete class that
instantiated it (SpecificList). Likewise if I had AnotherList:BaseList,
then when a user saves the layout of AnotherList, the code inside of
BaseList needs a way to get the string "AnotherList" out.

My thought is to add an abstract method to BaseList called
"GetConcreteClassName" or something like that. This would then force
all the subclasses of BaseList to implement the method. I believe that
there must be a more elegant solution than that. I would have to
believe that I could use reflection, but I'm not sure if this is a wise
approach or not. Is there a more OO way to figure this out?

Thanks,
Bill Gregg

*** Sent via Developersdex http://www.developersdex.com ***
Feb 14 '06 #1
6 1323
From the description, my understanding is that you have


System.Windows.Forms.Form
^
||
BaseList <>=== Grid
^
||
===============
|| ||
SpecificList AnotherList
BaseList
Overridable Sub LoadData()

SpecificList
Overrides Sub LoadData() - implements loading the grid for the
SpecificList data

AnotherList
Overrides Sub LoadData() - implements loading the grid for the
AnotherList data
Here is where I get a bit fuzzy

You say that want to store the layout uniquely for each 'Instance' of
BaseList but then start to talk about AnotherList.

Do you mean you want it to be unqiue for each concrete class?
Different layouts for SpecificList and AnotherList.

Or,

Do you mean that the user is able to save the layout of which list/grid
they are using irrespective of type?
Also, I'm afraid that I am not clear as to why the baselist code needs
to know the class name - for what are you using it.

Perhaps if you can post some more details we can be of help.
Alan.

Feb 14 '06 #2

Bill Gregg wrote:
I have an abstract class that is a windows form called "BaseList" that
contains a grid control. This grid control is then populated by any
concrete class that inherits from BaseList. I have a class SpecificList
class that is a kind of BaseList (class SpecificList:BaseList). When a
user interacts with the SpecificList, they will be allowed to save the
layout of that grid. Now, here's the rub.

I want to put the code into BaseList for storing the layout of the grid.
But I need to store the layout uniquely for each instance of BaseList.
In other words if I want to save the layout of SpecificList, the code
executed in BaseList needs to know the name of the concrete class that
instantiated it (SpecificList). Likewise if I had AnotherList:BaseList,
then when a user saves the layout of AnotherList, the code inside of
BaseList needs a way to get the string "AnotherList" out.


Why not make StoreLayout a method of BaseList then override it in each
inherited class? The base method can contain such layout-storing code
as is common to all lists, then each subclass' method calls the base
class method then adds its own details.

--
Larry Lard
Replies to group please

Feb 14 '06 #3
Alan,
Your object diagram is spot on, and your first assumption is the
correct one. When a user clicks on "StoreLayout" on the SpecificList
form, I want code in my BaseList class to store the layout in the
registry. These registry entries need to be unique for each kind of
concrete BaseList.

Ideally, I would like to be able to make all of my changes in BaseList
and not need to make a simple change in every concrete class that
derives from BaseList. I am trying to add functionality retroactively
and if I can avoid touching lots and lots of forms, I would like to.

Bill

*** Sent via Developersdex http://www.developersdex.com ***
Feb 14 '06 #4
Larry Lard wrote:

Why not make StoreLayout a method of BaseList then override it in each
inherited class? The base method can contain such layout-storing code
as is common to all lists, then each subclass' method calls the base
class method then adds its own details.

Bill Gregg writes:
The code for storing the layout is generic already. I can have a single
method handle all the additional functionality I need, I just need to
know the name of the concrete class that is inheriting from the BaseList
so that when I store the layout, I can associate the layout with the
form name.
*** Sent via Developersdex http://www.developersdex.com ***
Feb 14 '06 #5

You already have code in the base class for storing the layout and it
is sufficient to store the layout for each/every concrete class, all it
needs is a key/id with which to store/restore the given layout.

The simplest is to use the class name.

public void SaveLayout() {

string layoutID = this.GetType().Name;
Console.WriteLine(String.Format("Saving the layout for {0}.",
layoutID));

}
If we have two derived classes, Derived and AnotherDerived and call
SaveLayout on each

e.g.

Base b;

b = new Derived();
b.SaveLayout();

b = new AnotherDerived();
b.SaveLayout();

then we get

Saving the layout for Derived.
Saving the layout for AnotherDerived.

as the output.
hth,
Alan.

Feb 15 '06 #6

That worked perfectly well Alan. Thanks so much.

Bill Gregg
*** Sent via Developersdex http://www.developersdex.com ***
Feb 15 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: vcardillo | last post by:
Hello all, Okay, I am having some troubles. What I am doing here is dealing with an employee hierarchy that is stored in an array. It looks like this: $employees = array( "user_id" => array(...
1
by: Chris Lasher | last post by:
Hello, I'm trying to write a tool to scrape through some of the Ribosomal Database Project II's (http://rdp.cme.msu.edu/) pages, specifically, through the Hierarchy Browser....
0
by: archway | last post by:
Hi, I would like to build a hierarchy of ProductNode objects like so ProductNode ---Product Node ---ProductNode ------ProductNode ------ProductNode ---ProductNode
2
by: Matt | last post by:
Hello, I would like to generate what I call an "overall class hierarchy" in UML automatically derived from my C++ code source. An example of what I seek: ...
2
by: Yaro | last post by:
Hi All (UDB 8.1 FP8, Win) In my simple test database, I have two tables CREATE TABLE "DB2ADMIN"."AAA" ( "F1" INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY, "F2" VARCHAR(10), PRIMARY KEY...
4
by: Dave Veeneman | last post by:
I have an object hierarchy that's several layers deep, and I'm puzzling over how to access an object at any point in the hierarchy, solely by its key. The hierarchy is similar to an...
21
by: Mark Broadbent | last post by:
Consider the following statements //------- Item i = Basket.Items; //indexer is used to return instance of class Item Basket.Items.Remove(); //method on class item is fired item i = new...
2
by: Do | last post by:
Hi, I have a database table with the following fields: id, name, parentid. These fields are supposed to create a hierarchy for a list box, an infinite hierarchy Child fields of parent fields...
10
by: John Nagle | last post by:
Here are three network-related exceptions. These were caught by "except" with no exception type, because none of the more specific exceptions matched. This is what a traceback produced: 1....
3
by: krzysztof.konopko | last post by:
Hello! I want to design a class hierarchy with one base abstract class, let's say CBase. I have a predicate that every object in the class hierarchy must have a parent object of type from this...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.