473,804 Members | 3,399 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Designing 'value objects' in C#

Hi,

I'm currently trying to model a few complex data objects in C#. These
have a huge number of attributes which are manipulated in large blocks
by comparatively few API calls.

For maintainability , I've come up with creating nested structs that
contain the sets of attributes manipulated by one API call - so
currently the way to access actual attributes is something like
'theObject.Deta ils.Name' or 'theObject.Addi tionalDetails.T emplateID'.

The obvious way to design the 'Details' and 'AdditionalDeta ils'
properties would be as structs. However, this strikes me as an
inefficient solution, since every time a client access
'theObject.Deta ils.Something' a complete copy of the theObject.Detai ls
struct is created, only to be discarded immediately.

(If this is handled in a sane way by the runtime environment, it would
make me happy - however, I didn't have time to get into IL enough to
figure this out myself yet.)

What I'm looking for is something equivalent to the C++ const& semantics
for exposing structured properties. The only thing I've come up with is
something like

class Details
{
Details(string someAttribute, string someOtherAttrib ute)
{
SomeAttribute = someAttribute ;
SomeOtherAttrib ute = someOtherAttrib ute ;
}

public readonly string SomeAttribute ;
public readonly string SomeOtherAttrib ute ;
}

However, this is obviously a nightmare to maintain, since my structs
contain about 20 members each.

Any ideas on how to do this so that

- access to object.Details. Something is possible without copying
object.Details
- there is no way for a caller to change object.Details. Something
- I don't need to spend half of my time maintaining huge parameter
lists

?

thanks,
--
[*Thomas Themel*] The fundamental problem with vi is that it doesn't have
[extended contact] a mouse and therefore you've got all these commands.
[info provided in] - Bill Joy, <http://www.cs.pdx.edu/~kirkenda/joy84.html>
[*message header*]
Nov 15 '05 #1
2 5142
Thomas,

Like you said, you will create a copy every time. The only way around
this is to create a class, but like you said, it seems like an nightmare to
maintain.

I would stil use the class route, using read-only properties, but I
would write a program that would generate the code for you which you can
compile. Using reflection, you can scan a type (your structure), and then
have it spit out code which would expose the read-only properties which are
copied over from the structure (through the constructor perhaps). If you
want to get fancy, you can even write a static cast operator to your struct
to convert from your class to an instance of the struct and embed it in the
code.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Thomas Themel"
<th************ *************** *************** **********@isog sglei.iwoars.ne t
wrote in message news:sl******** *************** *************** *************** ***********@eri stoteles.iwoars .net... Hi,

I'm currently trying to model a few complex data objects in C#. These
have a huge number of attributes which are manipulated in large blocks
by comparatively few API calls.

For maintainability , I've come up with creating nested structs that
contain the sets of attributes manipulated by one API call - so
currently the way to access actual attributes is something like
'theObject.Deta ils.Name' or 'theObject.Addi tionalDetails.T emplateID'.

The obvious way to design the 'Details' and 'AdditionalDeta ils'
properties would be as structs. However, this strikes me as an
inefficient solution, since every time a client access
'theObject.Deta ils.Something' a complete copy of the theObject.Detai ls
struct is created, only to be discarded immediately.

(If this is handled in a sane way by the runtime environment, it would
make me happy - however, I didn't have time to get into IL enough to
figure this out myself yet.)

What I'm looking for is something equivalent to the C++ const& semantics
for exposing structured properties. The only thing I've come up with is
something like

class Details
{
Details(string someAttribute, string someOtherAttrib ute)
{
SomeAttribute = someAttribute ;
SomeOtherAttrib ute = someOtherAttrib ute ;
}

public readonly string SomeAttribute ;
public readonly string SomeOtherAttrib ute ;
}

However, this is obviously a nightmare to maintain, since my structs
contain about 20 members each.

Any ideas on how to do this so that

- access to object.Details. Something is possible without copying
object.Details
- there is no way for a caller to change object.Details. Something
- I don't need to spend half of my time maintaining huge parameter
lists

?

thanks,
--
[*Thomas Themel*] The fundamental problem with vi is that it doesn't have [extended contact] a mouse and therefore you've got all these commands.
[info provided in] - Bill Joy, <http://www.cs.pdx.edu/~kirkenda/joy84.html> [*message header*]

Nov 15 '05 #2
Nicholas Paldino [.NET/C# MVP] <ni************ **@exisconsulti ng.com>
wrote on 2003-09-15:
I would stil use the class route, using read-only properties, but I
would write a program that would generate the code for you which you can
compile. Using reflection, you can scan a type (your structure), and then
have it spit out code which would expose the read-only properties which are
copied over from the structure (through the constructor perhaps). If you
want to get fancy, you can even write a static cast operator to your struct
to convert from your class to an instance of the struct and embed it in the
code.


Thanks, I hadn't thought about this kind of stuff yet (being the old
fashioned C++ person that I am). I think I'll hack up something to
handle it this way.

ciao,
--
[*Thomas Themel*] "That which is novice-friendly is too frequently
[extended contact] expert-hostile, and vice versa."
[info provided in] - Tom Christiansen, crossposting
[*message header*] "GUIs considered harmful" to eight groups
Nov 15 '05 #3

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

Similar topics

6
2142
by: E G | last post by:
Hi! I am having problems in designing a class. First, I have a base class that allocates a 3D data set and allows some other mathematical operations with it, something like this: template <typename T> class BasicArray {
3
1335
by: alexhong2001 | last post by:
When design a class, should always make it "derivable" as a base class? Is there really a situation that the designed class not "derivable"? When should make a member "protected"? Only when allowing the derived class(es) directly access it? Should destructor always be virtual? Thanks for your comments!
1
1628
by: Naren | last post by:
Hello All, I am presently designing a cleint server architecture. I require some suggestions and help by the experts here. MyServer class conatins a list of Mysock class. class Myserver { private: list<Mysock> L1;
6
2402
by: Darren | last post by:
X-No-Archive Hi all, Can anyone help me with structuring the data in a small tool I have to build? I'm trying to work out if there's a design pattern or data structure that would remove some of the dependencies. I am designing an animation tool.
7
3644
by: Dave | last post by:
I have a system that basically stores a database within a database (I'm sure lots have you have done this before in some form or another). At the end of the day, I'm storing the actual data generically in a column of type nvarchar(4000), but I want to add support for unlimited text. I want to do this in a smart fashion. Right now I am leaning towards putting 2 nullable Value fields: ValueLong ntext nullable ValueShort nvarchar(4000)...
6
2955
by: Gary James | last post by:
This may not be a direct C# question, but since I'll be using using C# for development, I thought I'd pose the question here. I'll soon be involved in the design of a new software product that will employ a software "Plug-In" architecture. Taking the plug-in route will give us a design that can adapt to, as yet, undefined future requirements (within the scope of the plug-in interface spec of course). In the past I've done this with...
2
1420
by: Sky Sigal | last post by:
Hello: I'm currently messing around, and need as much feedback/help as I can get, trying to find the most economical/graceful way to build usercontrols that rely on styling to look any good... It's the last part that has got me all frazzled (the 'rely on...to look good')... Let me explain -- and please bear with me as it's a bit longer than my usual questions:
3
3333
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 class hierarchy but only objects of some of these types can be a parent. Example: class CFruit : public CBase { }; class CBranch : public CBase { };
1
10107
weaknessforcats
by: weaknessforcats | last post by:
Introduction Polymorphism is the official term for Object-Oriented Programming (OOP). Polymorphism is implemented in C++ by virtual functions. This article uses a simple example hierarchy which you may have seen many times in one form or another. An analysis of this example produces several problems that are not obvious but which will seriously limit your ability to use hierarchies like the example in a real program. Then, the article...
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10310
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5515
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4291
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 we have to send another system
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.