473,750 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Data structure and exception

I'm attempting to write a fairly complex data structure.

One part of the complexity is that all 8 data operations it supports
delegate some code to virtual method.

This is by design because I want the user to subclass the data structure and
be able to prevent changes to happen. and / or I want to notify observers.

The unfortunate side effect is: it seems there are no simple way to have all
user code run at the begining or at the end of the code.
Hence some user code might be called in the middle of an operation and cause
an unrecoverable error. (i.e. corrupt the data structure).

Do you think it's acceptable?

I am thinking there are 2 possibilities:

1. it's ok. Warn the user (in the documentation), these are critical data
method, mess them, mess the data!

2. data structure should be fool proof, stack all user change in a class for
this purpose and run them at the end

what do you think?
Jul 9 '06 #1
5 1513
do not worry, I think I solved it...

"Lloyd Dupont" <net.galador@ld wrote in message
news:u8******** ******@TK2MSFTN GP03.phx.gbl...
I'm attempting to write a fairly complex data structure.

One part of the complexity is that all 8 data operations it supports
delegate some code to virtual method.

This is by design because I want the user to subclass the data structure
and be able to prevent changes to happen. and / or I want to notify
observers.

The unfortunate side effect is: it seems there are no simple way to have
all user code run at the begining or at the end of the code.
Hence some user code might be called in the middle of an operation and
cause an unrecoverable error. (i.e. corrupt the data structure).

Do you think it's acceptable?

I am thinking there are 2 possibilities:

1. it's ok. Warn the user (in the documentation), these are critical data
method, mess them, mess the data!

2. data structure should be fool proof, stack all user change in a class
for this purpose and run them at the end

what do you think?


Jul 9 '06 #2
Lloyd Dupont wrote:
I'm attempting to write a fairly complex data structure.

One part of the complexity is that all 8 data operations it supports
delegate some code to virtual method.

This is by design because I want the user to subclass the data
structure and be able to prevent changes to happen. and / or I want
to notify observers.
The unfortunate side effect is: it seems there are no simple way to
have all user code run at the begining or at the end of the code.
Hence some user code might be called in the middle of an operation
and cause an unrecoverable error. (i.e. corrupt the data structure).

Do you think it's acceptable?

I am thinking there are 2 possibilities:

1. it's ok. Warn the user (in the documentation), these are critical
data method, mess them, mess the data!

2. data structure should be fool proof, stack all user change in a
class for this purpose and run them at the end

what do you think?
A good approach in situations like this is to separate the functionality of
your class from the extensibility points of your class. Rather than:

class Base
{
public vitrual void A() {}
}

use:

class Base
{
public void A()
{
// stuff that comes before the extension point
// (e.g. check invariants and pre-conditions, do base-class
processing)

OnA();

// stuff that comes after the extention point
// (e.g. check invariants and post-conditions)
}

protected virtual void OnA() {}
}

This way, your clients override OnA, but not A itself. You, as the
designer, retain control over where client code is inserted, so you can
still maintain (and check) invariants in the base class and know that
someone deriving from your class can't circumvent your checks by forgetting
to call the base class version (or by calling it in the wrong place).

-cd
Jul 9 '06 #3
Hi Carl, thanks for answering!

Anyway it's already like that but a bit more complex:

class Data
{
public void A()
{
B(); // if B() fail, C() will never happen
C();
OnA();
}
public virtual OnA() { /* potential adverse user code */ }
public void B()
{
// stuff ...
OnB();
}
public virtual OnB() { /* potential adverse user code */ }
public void C()
{
// stuff...
OnC();
}
public virtual OnC() { /* potential adverse user code */ }
}
// OnA(), OnB(), OnC() can't be removed, they are used by other part of the
API to track elementary change

However I was able to get around it.
All user notifications happen now in such a way that user exception let the
data in an unexpected, yet correct, state.
Although observers might get corrupted in the process, but it's not as
important/bad.

I no longer try to undo partial change (which could led to other exceptions
and I had no idea how to handle that correctly).

"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:eH******** *******@TK2MSFT NGP05.phx.gbl.. .
Lloyd Dupont wrote:
>I'm attempting to write a fairly complex data structure.

One part of the complexity is that all 8 data operations it supports
delegate some code to virtual method.

This is by design because I want the user to subclass the data
structure and be able to prevent changes to happen. and / or I want
to notify observers.
The unfortunate side effect is: it seems there are no simple way to
have all user code run at the begining or at the end of the code.
Hence some user code might be called in the middle of an operation
and cause an unrecoverable error. (i.e. corrupt the data structure).

Do you think it's acceptable?

I am thinking there are 2 possibilities:

1. it's ok. Warn the user (in the documentation), these are critical
data method, mess them, mess the data!

2. data structure should be fool proof, stack all user change in a
class for this purpose and run them at the end

what do you think?

A good approach in situations like this is to separate the functionality
of your class from the extensibility points of your class. Rather than:

class Base
{
public vitrual void A() {}
}

use:

class Base
{
public void A()
{
// stuff that comes before the extension point
// (e.g. check invariants and pre-conditions, do base-class
processing)

OnA();

// stuff that comes after the extention point
// (e.g. check invariants and post-conditions)
}

protected virtual void OnA() {}
}

This way, your clients override OnA, but not A itself. You, as the
designer, retain control over where client code is inserted, so you can
still maintain (and check) invariants in the base class and know that
someone deriving from your class can't circumvent your checks by
forgetting to call the base class version (or by calling it in the wrong
place).

-cd


Jul 10 '06 #4

The subject of objects invariats is quite a complex one. The Spec#
experimental language tries among others to solve this problem.

http://research.microsoft.com/specsharp/ You can find some very
interesting reading on the matter here.

I recomend starting with this slide
http://research.microsoft.com/specsh...ers/FM2005.ppt It explains
very clearly the problems with object invariants and the ways thei can
be solved.

Cheers!

Lloyd Dupont wrote:
I'm attempting to write a fairly complex data structure.

One part of the complexity is that all 8 data operations it supports
delegate some code to virtual method.

This is by design because I want the user to subclass the data structure and
be able to prevent changes to happen. and / or I want to notify observers.

The unfortunate side effect is: it seems there are no simple way to have all
user code run at the begining or at the end of the code.
Hence some user code might be called in the middle of an operation and cause
an unrecoverable error. (i.e. corrupt the data structure).

Do you think it's acceptable?

I am thinking there are 2 possibilities:

1. it's ok. Warn the user (in the documentation), these are critical data
method, mess them, mess the data!

2. data structure should be fool proof, stack all user change in a class for
this purpose and run them at the end

what do you think?
Jul 10 '06 #5
interesting, thanks!

--
Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>
"Pop Catalin" <po*********@gm ail.comwrote in message
news:11******** **************@ s13g2000cwa.goo glegroups.com.. .
>
The subject of objects invariats is quite a complex one. The Spec#
experimental language tries among others to solve this problem.

http://research.microsoft.com/specsharp/ You can find some very
interesting reading on the matter here.

I recomend starting with this slide
http://research.microsoft.com/specsh...ers/FM2005.ppt It explains
very clearly the problems with object invariants and the ways thei can
be solved.

Cheers!

Lloyd Dupont wrote:
>I'm attempting to write a fairly complex data structure.

One part of the complexity is that all 8 data operations it supports
delegate some code to virtual method.

This is by design because I want the user to subclass the data structure
and
be able to prevent changes to happen. and / or I want to notify
observers.

The unfortunate side effect is: it seems there are no simple way to have
all
user code run at the begining or at the end of the code.
Hence some user code might be called in the middle of an operation and
cause
an unrecoverable error. (i.e. corrupt the data structure).

Do you think it's acceptable?

I am thinking there are 2 possibilities:

1. it's ok. Warn the user (in the documentation), these are critical data
method, mess them, mess the data!

2. data structure should be fool proof, stack all user change in a class
for
this purpose and run them at the end

what do you think?

Jul 11 '06 #6

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

Similar topics

11
3188
by: theshowmecanuck | last post by:
As a matter of academic interest only, is there a way to programmatically list the 'c' data types? I am not looking for detail, just if it is possible, and what function could be used to accomplish it. For example: int main void() { while there are more data types { print next data type; }
9
1505
by: shadow.demon | last post by:
G'day, I've separated my database calls into a separate dll, and return results from any database calls as a SqlDataReader (because of SQL Server use, it's nice and fast). However I'd like to be database independent by replacing the dll with whatever database is being supported. This would mean instead of returning SqlDataReaders another way to return results would have to be used. Is the best method to return database neutral...
2
2357
by: James Radke | last post by:
Hello, I have a vb.net windows application that is calling an older DLL provided by a third party. They supplied a VB 6 application that, when run on my systemn successfully passes data to the database. The problem I am having is that when I pass the data from VB.NET, the fields defined as double all contain strange values. For example, if I pass in 10, the value stored on the database is: 5.325550197128e-315 Note that most of the...
8
3324
by: Charles Law | last post by:
Can anyone suggest how I would marshal a variable length structure back from an API call. Specifically, I am looking at the WaitForDebugEvent function, which returns a DEBUG_EVENT structure. However, the DEBUG_EVENT structure is defined as a union, and the size and contents vary depending on the event code contained in the header. typedef struct _DEBUG_EVENT { DWORD dwDebugEventCode; DWORD dwProcessId;
9
6651
by: MR | last post by:
I get the following Exception "The data at the root level is invalid. Line 1, position 642" whenever I try to deserialize an incoming SOAP message. The incoming message is formed well and its length is 642 bytes ( I have appended it to the end of this message). I suspect that the reason may have something to do with an incorrect declaration of which class to de-serialize to. In the attached code I substituted @@@@@@@ in the code below with...
5
1151
by: Lloyd Dupont | last post by:
I'm attempting to write a fairly complex data structure. One part of the complexity is that all 8 data operations it supports delegate some code to virtual method. This is by design because I want the user to subclass the data structure and be able to prevent changes to happen. and / or I want to notify observers. The unfortunate side effect is: it seems there are no simple way to have all user code run at the begining or at the end...
10
4042
by: Uma - Chellasoft | last post by:
Hai, I am new to VB.Net programming, directly doing socket programming. In C, I will be able to map the message arrived in a socket directly to a structure. Is this possible in VB.Net. Can anyone please help me with some sample codings and guidance? Can you also suggest some other news group available for socket programming in VB.Net?
31
7749
by: aarklon | last post by:
Hi all, this is a question which i saw in a book typedef struct mall_li_header_ { int refcnt; uchar pool; uchar flag; ushort magic_no; char data;
2
7207
by: O.B. | last post by:
When using Marshal to copy data from a byte array to the structure below, only the first byte of the "other" array is getting copied from the original byte array. What do I need to specify to get Marshal.PtrToStructure to copy the all the data into the "other" array? unsafe public struct DeadReckoning {
0
8999
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
9575
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9394
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
9338
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
9256
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
4712
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...
0
4885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
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
2798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.