473,511 Members | 14,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object design question (two, actually)

I'm working on a rewrite of our employee database. I plan to implement a
fairly heavyweight base class, which includes 20 or 30 fields, including
address and phone number collections and the like. (I'll use lazy init to
fill the collections when needed.) More specialized employee types would
inherit from the base class.

Sometimes, though, all I need is the employee name and ID number - for
example, when filling a DDL - and I hate to have all the overhead of creating
a heavyweight class object every time I want to look up an employee name by
ID. My question is: what's the best practice for doing very small lookups
like this? Should I create a small helper class, or use a lookup method in
the full class and just live with the overhead?

Along the same lines, I want to have an overloaded method that returns
various lists of employees (by role, active/inactive, etc). Do most people
feel that it breaks abstraction to have a method that returns multiple rows
in an object that represents a single entity? If so, where would a method
such as this live in the object hierarchy? I don't want to have to create
several classes for each separate type of object, but I want to do this the
right way.

Any thoughts would be appreciated..

Jul 21 '05 #1
5 1245
"Roger Bonine" <Ro*********@discussions.microsoft.com> wrote in message
news:6A**********************************@microsof t.com...
I'm working on a rewrite of our employee database. I plan to implement a
fairly heavyweight base class, which includes 20 or 30 fields, including
address and phone number collections and the like. (I'll use lazy init to
fill the collections when needed.) More specialized employee types
would
inherit from the base class.

Sometimes, though, all I need is the employee name and ID number - for
example, when filling a DDL
That sounds like a static GetEmployeeSummaries method, that returns a
collection of {ID, Name} tuples.
- and I hate to have all the overhead of creating
a heavyweight class object every time I want to look up an employee name
by
ID.
This sounds like a different usage - look up a single employee by ID. That
_does_ sound like it's time to instantiate the full Employee object.
My question is: what's the best practice for doing very small lookups
like this? Should I create a small helper class, or use a lookup method
in
the full class and just live with the overhead?
What overhead? I'd put it in the base class, to the extent that the base
class should understand the various sets of Employees. For instance, it
makes sense for a base Employee class to be able to enumerate all employees,
but it doesn't make sense for it to be able to enumerate some subset of
Employees where the criteria aren't held in the base class.
Along the same lines, I want to have an overloaded method that returns
various lists of employees (by role, active/inactive, etc). Do most
people
feel that it breaks abstraction to have a method that returns multiple
rows
in an object that represents a single entity?
No, it doesn't break abstraction, because ...
If so, where would a method
such as this live in the object hierarchy? I don't want to have to
create
several classes for each separate type of object, but I want to do this
the
right way.


.... because you need to have some sort of factory system. If you're going to
have multiple types of Employee, you're going to need a way to create the
correct derived class instance based on the data in the database. So, it
wouldn't break abstraction, because anything the base Employee class does
about creating lists of Employees would be in terms of the factory, which
could create whatever kind of employee was necessary.

On the other hand, you'll want to consider whether these lists of Employees
need to be lists of Employees, or whether they could be lists of
EmployeeSummary objects (ID, Name), from which the real Employee could be
retrieved if necessary. Hmm... Maybe the base Employee class could use lazy
init to load its 30 fields but always get the id and name?

John Saunders
Jul 21 '05 #2
"John Saunders" wrote:
- and I hate to have all the overhead of creating
a heavyweight class object every time I want to look up an employee name
by ID.
This sounds like a different usage - look up a single employee by ID. That
_does_ sound like it's time to instantiate the full Employee object.


By instantiate the full object, do you mean do a full Get(), or just have
some sort of LookupNameByID method? A full Get seems pretty wasteful if I
don't need most of the information. I was actually thinking of just
overriding ToString in this particular case, with overloads for the different
name types (LastFirst, etc).
My question is: what's the best practice for doing very small lookups
like this? Should I create a small helper class, or use a lookup method
in
the full class and just live with the overhead?


What overhead? I'd put it in the base class, to the extent that the base
class should understand the various sets of Employees. For instance, it
makes sense for a base Employee class to be able to enumerate all employees,
but it doesn't make sense for it to be able to enumerate some subset of
Employees where the criteria aren't held in the base class.


The overhead that I was concerned about is mostly having to declare the
member variables for the properties. If I have, say, 45 properties, I didn't
want to have to declare all of those member vars for no reason when I only
care about a couple of values. It may not be a big deal in the grand scheme
of things, but I just wasn't sure about the best practice.

Thanks for your help!

Jul 21 '05 #3
Sounds like you would like to implement a proxy design pattern
http://c2.com/cgi/wiki?ProxyPattern.

Not really sure what you want to avoid in your second question, perhaps an
example would help me.

Warm Regards,
Dan
"Roger Bonine" <Ro*********@discussions.microsoft.com> wrote in message
news:6A**********************************@microsof t.com...
I'm working on a rewrite of our employee database. I plan to implement a
fairly heavyweight base class, which includes 20 or 30 fields, including
address and phone number collections and the like. (I'll use lazy init to
fill the collections when needed.) More specialized employee types would inherit from the base class.

Sometimes, though, all I need is the employee name and ID number - for
example, when filling a DDL - and I hate to have all the overhead of creating a heavyweight class object every time I want to look up an employee name by ID. My question is: what's the best practice for doing very small lookups like this? Should I create a small helper class, or use a lookup method in the full class and just live with the overhead?

Along the same lines, I want to have an overloaded method that returns
various lists of employees (by role, active/inactive, etc). Do most people feel that it breaks abstraction to have a method that returns multiple rows in an object that represents a single entity? If so, where would a method such as this live in the object hierarchy? I don't want to have to create several classes for each separate type of object, but I want to do this the right way.

Any thoughts would be appreciated..

Jul 21 '05 #4
"Roger Bonine" <Ro*********@discussions.microsoft.com> wrote in message
news:56**********************************@microsof t.com...
"John Saunders" wrote:
>- and I hate to have all the overhead of creating
> a heavyweight class object every time I want to look up an employee
> name
> by ID.


This sounds like a different usage - look up a single employee by ID.
That
_does_ sound like it's time to instantiate the full Employee object.


By instantiate the full object, do you mean do a full Get(), or just have
some sort of LookupNameByID method? A full Get seems pretty wasteful if I
don't need most of the information. I was actually thinking of just
overriding ToString in this particular case, with overloads for the
different
name types (LastFirst, etc).


I misread your post. I thought you said "look up an employee", but I now see
that you said "look up an employee name".

No, just have a static Employee.GetNameByID(id) method, or something like
that.
> My question is: what's the best practice for doing very small lookups
> like this? Should I create a small helper class, or use a lookup
> method
> in
> the full class and just live with the overhead?


What overhead? I'd put it in the base class, to the extent that the base
class should understand the various sets of Employees. For instance, it
makes sense for a base Employee class to be able to enumerate all
employees,
but it doesn't make sense for it to be able to enumerate some subset of
Employees where the criteria aren't held in the base class.


The overhead that I was concerned about is mostly having to declare the
member variables for the properties. If I have, say, 45 properties, I
didn't
want to have to declare all of those member vars for no reason when I only
care about a couple of values. It may not be a big deal in the grand
scheme
of things, but I just wasn't sure about the best practice.


Ok, now that I see that you were just talking about the name, forget I asked
that!

John Saunders
Jul 21 '05 #5


"John Saunders" wrote:
"Roger Bonine" <Ro*********@discussions.microsoft.com> wrote in message
news:56**********************************@microsof t.com...
"John Saunders" wrote:
>- and I hate to have all the overhead of creating
> a heavyweight class object every time I want to look up an employee
> name
> by ID.

This sounds like a different usage - look up a single employee by ID.
That
_does_ sound like it's time to instantiate the full Employee object.


By instantiate the full object, do you mean do a full Get(), or just have
some sort of LookupNameByID method? A full Get seems pretty wasteful if I
don't need most of the information. I was actually thinking of just
overriding ToString in this particular case, with overloads for the
different
name types (LastFirst, etc).


I misread your post. I thought you said "look up an employee", but I now see
that you said "look up an employee name".

No, just have a static Employee.GetNameByID(id) method, or something like
that.

> My question is: what's the best practice for doing very small lookups
> like this? Should I create a small helper class, or use a lookup
> method
> in
> the full class and just live with the overhead?

What overhead? I'd put it in the base class, to the extent that the base
class should understand the various sets of Employees. For instance, it
makes sense for a base Employee class to be able to enumerate all
employees,
but it doesn't make sense for it to be able to enumerate some subset of
Employees where the criteria aren't held in the base class.


The overhead that I was concerned about is mostly having to declare the
member variables for the properties. If I have, say, 45 properties, I
didn't
want to have to declare all of those member vars for no reason when I only
care about a couple of values. It may not be a big deal in the grand
scheme
of things, but I just wasn't sure about the best practice.


Ok, now that I see that you were just talking about the name, forget I asked
that!

John Saunders


Thanks for your help!
Jul 21 '05 #6

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

Similar topics

12
2375
by: R | last post by:
Hello everybody. I'm writing my own Content System in PHP5. I've written so far main classes for handling DB connections, XML, XForms and Sessions. But I've got problem with one thing - it's...
36
6323
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but...
4
2192
by: Stanimir Stamenkov | last post by:
I have this kind of construct: http://www.geocities.com/stanio/temp/usemap01.html (an IMG element using MAP described with AREA elements) I'm trying to make it more accessible and currently...
5
2636
by: Christopher D. Wiederspan | last post by:
This is a bit tough to figure out the best way to ask, but here it goes. I've got a class, say MyObject, and everytime this class is instanciated, I actually want to get a reference to an existing...
12
5505
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
79
3706
by: VK | last post by:
I wandering about the common proctice of some UA's producers to spoof the UA string to pretend to be another browser (most often IE). Shouldn't it be considered as a trademark violation of the...
12
7478
by: Doug | last post by:
Hi, I learned a little about the model view presenter pattern at a conference this last week and am experimenting with it. It's working pretty well but I have a question. I am trying to use...
3
2288
by: Kevin | last post by:
Using this: http://msdn2.microsoft.com/en-us/library/3dasc8as(VS.80).aspx as an example I have a question concerning the reuse of objects. In the example 10 instances of the Fibonacci class...
14
2495
by: =?GB2312?B?zPC5zw==?= | last post by:
Howdy, I wonder why below does not work. a = object() a.b = 1 # dynamic bind attribute failed... To make it correct, we have to create a new class: class MyClass(object): pass a =...
3
157
by: H. S. Lahman | last post by:
Responding to siddharthkhare... Ignore Topmind and frebe. They are anti-OO P/R guys. Let's not confuse things with specific 3GL syntax. At the OOA/D level the model looks like: | 1
0
7237
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
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5659
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
3219
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
445
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.