473,326 Members | 2,111 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,326 software developers and data experts.

Simple pattern for representing a view of a domain object?

This is something I've tried to solve a number of different ways, wanted
people's opinion on how they solve it.

I have a class, say users, which has a bunch of properties/methods. Problem
is I want to make available only a subset of this information, say I want to
have a list of "online users" which only makes use of the username and id.

Problem is, I don't want to have to load the entire object. In a sense, I
want to create a view of the object with only certain properties exposed. I
don't want to use lazy loading. I don't want to reuse my user class as is
and only partially load it, because that would result in weird behaviour
(ie, the "FullName" property is exposed, but doesn't work).

One of the ways I've handled this is to use a quasi-proxy. Something like
UserView which is composed of a User object. In this case the User object
is only partially loaded (via some specific internal calls to dal). That
isn't a problem because that's hidden from the consumer. The UserView class
doesn't expose the property of the User class which won't be loaded, so
there's no confusion.

I've also done the inverse. Where my User class would be composed of the
UserView class. This to me is a more tranditional form of composition, but
it doesn't fit as well with this "view" way that I'm thinking.

Not too crazy about the word view for XXXView either :)

Anyways, anyone doing something better than that? :)

karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!


Dec 9 '05 #1
1 872
KJ
Hello Karl,

Sounds like you got a lot of all the bases covered. But one thing you
didn't mention was the use of interfaces.

Your "user" class could implement multiple interfaces, and the
consumers of it would thus only consume it as an instance of one of
those interfaces (i.e., as the interface appropriate to the context).

In this way, casted to interface A, the consumer of "user" only has
access to the props/methods listed in A. "User" thus takes on multiple
identities.

Add a special set of "initialize" methods to the code, each
initializing the props corresponding to one of the interfaces. In this
way, you can lazy-instantiate only the props corresponding to the
required interface. This type of setup might also require an
intermediary class that hands out the appropriately casted (to the
interface) versions of the object to the consumer (something like a
factory).

I would also consider when taking approaches such as this that you make
sure that any programmers who take over this code know what's going on,
since it's probably going to be somewhat on the non-standard side.

It might be easier just to create multiple classes, since that is
actually the net effect of such behavior, except that that is much more
understandable to the end user than these other interesting
machinations.

p.s. Another NG useful for such discussions is comp.object

-KJ

Dec 9 '05 #2

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

Similar topics

21
by: Sharon | last post by:
I wish to build a framework for our developers that will include a singleton pattern. But it can not be a base class because it has a private constructor and therefore can be inherit. I thought...
13
by: Robert W. | last post by:
At the beginning of my C# days (about 6 months ago) I learned about the Singleton pattern and implemented for Reference data, such as the kind that appears in an Options dialog box. My Singleton...
0
by: headware | last post by:
In his book "Patterns of Enterprise Application Architecture", Martin Fowler says that using the Table Module pattern to model the domain logic precludes the use of inheritance and GoF style OO...
2
by: Martin | last post by:
Hi, I want to create a number of ascx controls with edit and view modes. Previously I have put two panels in the ascx - one for view (with label subcontrols), and one for edit (with text box...
1
by: Marcel Hug | last post by:
Hi NG ! I have already written a task about MVC and I tried to get the best informations together. I would like to implement the MVC pattern and it work on the way I did it. At first i know the...
7
by: INeedADip | last post by:
I want to get some feedback so don't hold back. I have a webservice that is responsible for Formatting a ton of information that is then queried by other applications (agents) that utilize it...
4
by: Shawnk | last post by:
This post is intended to verify that true value semantics DO NOT EXIST for the Enum class (relative to boolean operations). If this is true then (thus and therefore) you can not design state...
26
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is...
6
by: Karthik V | last post by:
I've been facing this situation often: class NewFeature { TheClass *theClass; NewFeature(TheClass *t) { theClass = t; } void act() { // call methods on theClass } }
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.