473,322 Members | 1,347 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,322 software developers and data experts.

the use of interface is prohibited with struct

I am have pretty light types whose object I would like to use for
serialization thus ensure they obey the contract. Apparently, I cannot
use structs and have no choice, but to you use class.

thoughts?
Oct 8 '08 #1
7 915
puzzlecracker wrote:
I am have pretty light types whose object I would like to use for
serialization thus ensure they obey the contract. Apparently, I cannot
use structs and have no choice, but to you use class.
Use classes.

I would be very surprised if you could measure a performance difference
in the real app.

Arne
Oct 8 '08 #2
On Tue, 07 Oct 2008 19:08:16 -0700, puzzlecracker <ir*********@gmail.com>
wrote:
I am have pretty light types whose object I would like to use for
serialization thus ensure they obey the contract. Apparently, I cannot
use structs and have no choice, but to you use class.
Can you elaborate? Your question seems to be asking why you can't write a
struct that implements a particular interface. But you can, so it seems
you must be asking some other question that's not immediately apparent.

Can you post some code that doesn't work, but which you'd like it to?

Pete
Oct 8 '08 #3
On Oct 7, 10:40 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Tue, 07 Oct 2008 19:08:16 -0700, puzzlecracker <ironsel2...@gmail.com>
wrote:
I am have pretty light types whose object I would like to use for
serialization thus ensure they obey the contract. Apparently, I cannot
use structs and have no choice, but to you use class.

Can you elaborate? Your question seems to be asking why you can't write a
struct that implements a particular interface. But you can, so it seems
you must be asking some other question that's not immediately apparent.

Can you post some code that doesn't work, but which you'd like it to?

Pete
Hmm, I will try it tomorrow at work, and if it's true, I will do a lot
of changes, as I am accustomed to using a struct whenever I
declare member variables public.
Oct 8 '08 #4
On Tue, 07 Oct 2008 20:02:36 -0700, puzzlecracker <ir*********@gmail.com>
wrote:
Hmm, I will try it tomorrow at work, and if it's true, I will do a lot
of changes, as I am accustomed to using a struct whenever I
declare member variables public.
You should never declare member variables public. Make them properties.

Every rule has its exceptions, including this one. But it's a good rule
to live by.

Beyond, the question of whether a member field is public or not isn't IMHO
a good metric for deciding whether a type should be a struct or a class.
Doing it that way would be kind of like voting for a politician based
solely on their gender or race.

Pete
Oct 8 '08 #5
On Oct 7, 11:20*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Tue, 07 Oct 2008 20:02:36 -0700, puzzlecracker <ironsel2...@gmail.com>*
wrote:
Hmm, I will try it tomorrow at work, and if it's true, I will do a lot
of changes, as * I am accustomed *to using *a struct whenever I
declare member variables public.

You should never declare member variables public. *Make them properties..

Every rule has its exceptions, including this one. *But it's a good rule *
to live by.

Beyond, the question of whether a member field is public or not isn't IMHO *
a good metric for deciding whether a type should be a struct or a class. *
Doing it that way would be kind of like voting for a politician based *
solely on their gender or race.

Pete
Well, what do you suggest to use when I have a types with very few
members whose sole purpose to set/get and serialize (ReadObject,
WriteObject)? This is sort of a design question

Thanks
Oct 8 '08 #6
On Oct 8, 2:21*pm, puzzlecracker <ironsel2...@gmail.comwrote:

<snip>
Well, what do you suggest to use when I have a types with very few
members whose sole purpose to set/get and serialize (ReadObject,
WriteObject)? This is sort of a design question
Public properties, private variables. That way you retain control.

Jon
Oct 8 '08 #7
On Wed, 08 Oct 2008 06:21:23 -0700, puzzlecracker <ir*********@gmail.com>
wrote:
>You should never declare member variables public. Â*Make them properties.

[...]

Well, what do you suggest to use when I have a types with very few
members whose sole purpose to set/get and serialize (ReadObject,
WriteObject)? This is sort of a design question
As I said before, use public properties. You can either back them with
private fields as Jon suggests, or just make them automatic properties and
let the compiler take care of it.
Oct 8 '08 #8

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

Similar topics

1
by: Steve Juranich | last post by:
I'm in the process of writing a few extension types, and there's one that I'd sort of like to have getitem, setitem, getslice, setslice functionality for. I've been looking through the docs and...
1
by: Lincoln Yeoh | last post by:
Hi, If I have a program listening on 0.0.0.0:(someport) on all interfaces, how do I know which network interface a broadcast packet is coming in on - assuming Linux and _many_ interfaces. And...
3
by: New Comer | last post by:
Can somebody compare Abstract Class and Interface for me? Thanks
2
by: David | last post by:
hello... how can i use IActiveDesktop COM interface from shell32.dll? thanx...
17
by: Zytan | last post by:
Aren't all classes interfaces? What constitutes an interface (and with it, the "I" prefix distinction)? Zytan
3
by: goodmen | last post by:
I think the boost::concept_check is too complex. Here is my solution about static interface and concept. The static interface can be used as function param. It is just a proxy of the real...
1
by: yadolov | last post by:
I have COM-object with Iface interface: typedef struct { .... } TStruct; interface Iface : IUnknown {
6
by: Chris Carlen | last post by:
Hi: I have an embedded system, platform: TI TMS320F2812 32-bit integer DSP. A module (.c file) contains external (to the funcs in that module) variables which are used to affect the operation...
1
by: recherche | last post by:
Hola! I tried the following public implementation of interface indexer by struct (Code Snippet 1) in private and explicit implementation by struct (Code Snippet 2) but in vain. Please help! ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: 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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.