If I have two custom vb.net classes, where 80% of the properties are alike
and there is one method with a matching signature, can i cast between one
and the other? do i need to have each class implement a common interface?
thanks,
craig buchanan 14 2289
No and Yes.
You should either define an interface or a common base class (same concept
really). Then you can access the derived class methods through references
to the base class.
"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:eQ****************@TK2MSFTNGP11.phx.gbl... If I have two custom vb.net classes, where 80% of the properties are alike and there is one method with a matching signature, can i cast between one and the other? do i need to have each class implement a common interface?
thanks,
craig buchanan
"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:eQ****************@TK2MSFTNGP11.phx.gbl... If I have two custom vb.net classes, where 80% of the properties are alike and there is one method with a matching signature, can i cast between one and the other? do i need to have each class implement a common interface?
Yep... or they inherit from the same parent... In which case those common
methods would be overridden (sp?) by the child classes, and then you could
cast to the parent type, but not directly between the types.
Interface would be fine too...
thanks,
craig buchanan
Craig,
BEWARE!!!
You could go the base class/interface route, but is that the "correct"
architectural decision. Are these two classes REALLY two subtypes of
another, more generic thing (inheritance)? Or do they both conform the same
contract (interfaces)?
Instead, you could create some sort of observer/inspector class that knows
how get the required information from your two classes. This keeps your
classes pure if inheritance/interface implementation it not called for.
Just a thought,
Andrew J. Marshall
MCP (Visual Basic)
Fairfax, VA
"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:eQ****************@TK2MSFTNGP11.phx.gbl... If I have two custom vb.net classes, where 80% of the properties are alike and there is one method with a matching signature, can i cast between one and the other? do i need to have each class implement a common interface?
thanks,
craig buchanan
"Andrew J. Marshall" <An*************@ObjectVision.netANTISPAMDEVICE> wrote
in message news:uR****************@TK2MSFTNGP10.phx.gbl... Craig,
BEWARE!!!
You could go the base class/interface route, but is that the "correct" architectural decision. Are these two classes REALLY two subtypes of another, more generic thing (inheritance)? Or do they both conform the
same contract (interfaces)?
Instead, you could create some sort of observer/inspector class that knows how get the required information from your two classes. This keeps your classes pure if inheritance/interface implementation it not called for.
What the hell are you talking about?
Just a thought, Andrew J. Marshall MCP (Visual Basic) Fairfax, VA
"Craig Buchanan" <so*****@somewhere.com> wrote in message news:eQ****************@TK2MSFTNGP11.phx.gbl... If I have two custom vb.net classes, where 80% of the properties are
alike and there is one method with a matching signature, can i cast between
one and the other? do i need to have each class implement a common
interface? thanks,
craig buchanan
if i create an interface and implement in each class, and i cast from one to
the other, only the property represented by the interface will be preserved
in the target class, right?
craig
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:c1*******************@news.demon.co.uk... No and Yes.
You should either define an interface or a common base class (same concept really). Then you can access the derived class methods through references to the base class.
"Craig Buchanan" <so*****@somewhere.com> wrote in message news:eQ****************@TK2MSFTNGP11.phx.gbl... If I have two custom vb.net classes, where 80% of the properties are
alike and there is one method with a matching signature, can i cast between
one and the other? do i need to have each class implement a common
interface? thanks,
craig buchanan
Lol -
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.com... "Andrew J. Marshall" <An*************@ObjectVision.netANTISPAMDEVICE>
wrote in message news:uR****************@TK2MSFTNGP10.phx.gbl... Craig,
BEWARE!!!
You could go the base class/interface route, but is that the "correct" architectural decision. Are these two classes REALLY two subtypes of another, more generic thing (inheritance)? Or do they both conform the same contract (interfaces)?
Instead, you could create some sort of observer/inspector class that
knows how get the required information from your two classes. This keeps your classes pure if inheritance/interface implementation it not called for.
What the hell are you talking about?
Just a thought, Andrew J. Marshall MCP (Visual Basic) Fairfax, VA
"Craig Buchanan" <so*****@somewhere.com> wrote in message news:eQ****************@TK2MSFTNGP11.phx.gbl... If I have two custom vb.net classes, where 80% of the properties are alike and there is one method with a matching signature, can i cast between one and the other? do i need to have each class implement a common interface? thanks,
craig buchanan
You don't cast to the other class, you cast to the interface...
and right.. only those common will be accessible through the interface
itself, but you could always recast it if so desired, but, thats kinda
pointless now isn't it. =)
"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:eO****************@tk2msftngp13.phx.gbl... if i create an interface and implement in each class, and i cast from one
to the other, only the property represented by the interface will be
preserved in the target class, right?
craig
"Robin Tucker" <id*************************@reallyidont.com> wrote in message news:c1*******************@news.demon.co.uk... No and Yes.
You should either define an interface or a common base class (same
concept really). Then you can access the derived class methods through
references to the base class.
"Craig Buchanan" <so*****@somewhere.com> wrote in message news:eQ****************@TK2MSFTNGP11.phx.gbl... If I have two custom vb.net classes, where 80% of the properties are alike and there is one method with a matching signature, can i cast between one and the other? do i need to have each class implement a common interface? thanks,
craig buchanan
* "Craig Buchanan" <so*****@somewhere.com> scripsit: If I have two custom vb.net classes, where 80% of the properties are alike and there is one method with a matching signature, can i cast between one and the other? do i need to have each class implement a common interface?
Both classes will have to implement a common interface and/or inherit
from the same base class.
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet/>
"Andrew J. Marshall" <An*************@ObjectVision.netANTISPAMDEVICE> wrote
in message news:%2***************@TK2MSFTNGP12.phx.gbl... LOL as well!!!
I'm just trying to impress an obvious beginner that inheritance isn't
always the right thing to do. In fact it's the wrong thing to do.
Again... I reiterate... what the hell are you talking about?
Just because my implementations of Moose and Pig share 80% of the same functionality (namely Burp, Defecate and Urinate), doesn't mean I should create a BurperDefecaterAndUrinator class/interface for them to inherit/implement.
Why wouldn't you? That is actually a perfect example of using inheritance,
espeically implementation inheritance. I begin to question who is the
obvious beginner...
That's what the hell I'm talking about, BABY! 8-)
Andrew J. Marshall MCP (Visual Basic) Fairfax, VA
"Robin Tucker" <id*************************@reallyidont.com> wrote in message news:c1*******************@news.demon.co.uk... Lol -
"CJ Taylor" <no****@blowgoats.com> wrote in message news:10*************@corp.supernews.com... "Andrew J. Marshall" <An*************@ObjectVision.netANTISPAMDEVICE>
wrote in message news:uR****************@TK2MSFTNGP10.phx.gbl... > Craig, > > BEWARE!!! > > You could go the base class/interface route, but is that the
"correct" > architectural decision. Are these two classes REALLY two subtypes of > another, more generic thing (inheritance)? Or do they both conform
the same > contract (interfaces)? > > Instead, you could create some sort of observer/inspector class that knows > how get the required information from your two classes. This keeps your > classes pure if inheritance/interface implementation it not called for. >
What the hell are you talking about?
> Just a thought, > Andrew J. Marshall > MCP (Visual Basic) > Fairfax, VA > > "Craig Buchanan" <so*****@somewhere.com> wrote in message > news:eQ****************@TK2MSFTNGP11.phx.gbl... > > If I have two custom vb.net classes, where 80% of the properties
are alike > > and there is one method with a matching signature, can i cast between one > > and the other? do i need to have each class implement a common interface? > > > > thanks, > > > > craig buchanan > > > > > >
Hi CJ, Just because my implementations of Moose and Pig share 80% of the same functionality (namely Burp, Defecate and Urinate), doesn't mean I should create a BurperDefecaterAndUrinator class/interface for them to inherit/implement.
Some believe that Darwin was right, some tell he is totaly wrong, I think
this is not the newsgroup to discus about that.
But just my thoughts.
:-))
(I think he was right by the way)
Cor
Hehe...
I agree.
=)
"Cor" <no*@non.com> wrote in message
news:ej*************@tk2msftngp13.phx.gbl... Hi CJ,
Just because my implementations of Moose and Pig share 80% of the same functionality (namely Burp, Defecate and Urinate), doesn't mean I
should create a BurperDefecaterAndUrinator class/interface for them to inherit/implement.
Some believe that Darwin was right, some tell he is totaly wrong, I think this is not the newsgroup to discus about that.
But just my thoughts.
:-))
(I think he was right by the way)
Cor
Not trying to offend you or anything... just letting you know your telling
people the wrong things...
I'm glad you contribute... but, this is one of those times you were just
flat out wrong.. I'm wrong too (alot) and Cor/Herfried let me know.. or
Peter Huang, but he doesn't count.
-CJ
"Andrew J. Marshall" <An*************@ObjectVision.netANTISPAMDEVICE> wrote
in message news:%2***************@TK2MSFTNGP12.phx.gbl... LOL as well!!!
I'm just trying to impress an obvious beginner that inheritance isn't
always the right thing to do. In fact it's the wrong thing to do.
Just because my implementations of Moose and Pig share 80% of the same functionality (namely Burp, Defecate and Urinate), doesn't mean I should create a BurperDefecaterAndUrinator class/interface for them to inherit/implement.
That's what the hell I'm talking about, BABY! 8-)
Andrew J. Marshall MCP (Visual Basic) Fairfax, VA
"Robin Tucker" <id*************************@reallyidont.com> wrote in message news:c1*******************@news.demon.co.uk... Lol -
"CJ Taylor" <no****@blowgoats.com> wrote in message news:10*************@corp.supernews.com... "Andrew J. Marshall" <An*************@ObjectVision.netANTISPAMDEVICE>
wrote in message news:uR****************@TK2MSFTNGP10.phx.gbl... > Craig, > > BEWARE!!! > > You could go the base class/interface route, but is that the
"correct" > architectural decision. Are these two classes REALLY two subtypes of > another, more generic thing (inheritance)? Or do they both conform
the same > contract (interfaces)? > > Instead, you could create some sort of observer/inspector class that knows > how get the required information from your two classes. This keeps your > classes pure if inheritance/interface implementation it not called for. >
What the hell are you talking about?
> Just a thought, > Andrew J. Marshall > MCP (Visual Basic) > Fairfax, VA > > "Craig Buchanan" <so*****@somewhere.com> wrote in message > news:eQ****************@TK2MSFTNGP11.phx.gbl... > > If I have two custom vb.net classes, where 80% of the properties
are alike > > and there is one method with a matching signature, can i cast between one > > and the other? do i need to have each class implement a common interface? > > > > thanks, > > > > craig buchanan > > > > > >
Aw crap, my bad.
I meant to say "In fact, *SOMETIMES* it's the wrong thing to do."
(NOTE: I must have looked like a complete idiot, instead of the partial
idiot that I am.)
Anyway, please don't tell me you think inheritance is right ALL the time.
What should I do when I want my Moose and Pig classes to have Flatulate
methods, add that to my BurperDefecaterAndUrinator class? But wait, my
Jabberwocky class also inherits from BurperDefecaterAndUrinator (because it
LOVES to do those things!), but due to a cruel evolutionary twist can not
generate flatulence. Now what?
I'm just trying to get Craig to think about alternatives that might not have
such a "permanent" impact on his code/architecture.
Andrew J. Marshall
MCP (Visual Basic)
Fairfax, VA
p.s. Offense only partly taken - given that this is a public forum, you
could (should?) have said "This seems like a radical comment. Could you
please explain in more detail?" That said, it was still funny as hell!
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.com... Not trying to offend you or anything... just letting you know your telling people the wrong things...
I'm glad you contribute... but, this is one of those times you were just flat out wrong.. I'm wrong too (alot) and Cor/Herfried let me know.. or Peter Huang, but he doesn't count.
-CJ
"Andrew J. Marshall" <An*************@ObjectVision.netANTISPAMDEVICE>
wrote in message news:%2***************@TK2MSFTNGP12.phx.gbl... LOL as well!!!
I'm just trying to impress an obvious beginner that inheritance isn't always the right thing to do. In fact it's the wrong thing to do.
Just because my implementations of Moose and Pig share 80% of the same functionality (namely Burp, Defecate and Urinate), doesn't mean I should create a BurperDefecaterAndUrinator class/interface for them to inherit/implement.
That's what the hell I'm talking about, BABY! 8-)
Andrew J. Marshall MCP (Visual Basic) Fairfax, VA
"Robin Tucker" <id*************************@reallyidont.com> wrote in message news:c1*******************@news.demon.co.uk... Lol -
"CJ Taylor" <no****@blowgoats.com> wrote in message news:10*************@corp.supernews.com... > > "Andrew J. Marshall"
<An*************@ObjectVision.netANTISPAMDEVICE> wrote > in message news:uR****************@TK2MSFTNGP10.phx.gbl... > > Craig, > > > > BEWARE!!! > > > > You could go the base class/interface route, but is that the "correct" > > architectural decision. Are these two classes REALLY two subtypes
of > > another, more generic thing (inheritance)? Or do they both conform the > same > > contract (interfaces)? > > > > Instead, you could create some sort of observer/inspector class
that knows > > how get the required information from your two classes. This keeps your > > classes pure if inheritance/interface implementation it not called for. > > > > What the hell are you talking about? > > > Just a thought, > > Andrew J. Marshall > > MCP (Visual Basic) > > Fairfax, VA > > > > "Craig Buchanan" <so*****@somewhere.com> wrote in message > > news:eQ****************@TK2MSFTNGP11.phx.gbl... > > > If I have two custom vb.net classes, where 80% of the properties are > alike > > > and there is one method with a matching signature, can i cast between > one > > > and the other? do i need to have each class implement a common > interface? > > > > > > thanks, > > > > > > craig buchanan > > > > > > > > > > > >
Andrew,
Not a problem at all. I know that some of us (especially me) come off
rather coarse sometimes. But remember, its hard to express emotion on here
too.. I wasn't upset with you, was just like jokingly thinking, what on
earth are you talking about. Aw crap, my bad.
I meant to say "In fact, *SOMETIMES* it's the wrong thing to do."
This is true...
(NOTE: I must have looked like a complete idiot, instead of the partial idiot that I am.)
Anyway, please don't tell me you think inheritance is right ALL the time.
By no means is inheritance correct at all times. Appleman covers this topic
many times in his books (I like Dan, he's a good author), and in fact it can
be dangerous to use it if you don't know how/why your using inheritance.
A lot of people use it because it's the "IN" thing in programming (if there
is such a thing) and apparently if you use inheritance it makes you a better
programmer. Yes and no. Yes, if you can explain WHY you used inheritance.
What should I do when I want my Moose and Pig classes to have Flatulate methods, add that to my BurperDefecaterAndUrinator class? But wait, my Jabberwocky class also inherits from BurperDefecaterAndUrinator (because
it LOVES to do those things!), but due to a cruel evolutionary twist can not generate flatulence. Now what?
And you bring up an excellent point right there. What to do? Humans are
interesting creatures (sometimes amazes me how we built these amazing
machines) because we tend to try to simplify things based on
repition/previous results. i.e. take your going to the bathroom idea, do
you think about having to get up, then walk x steps, lift toilet seat (if
your a man... and married...) and THEN do your business? Nope... we just
want to make it as easy as possible and don't really think about it. Now,
if computers could do this it would be great, and they can but because of
programmers. =)
So, what is to say we cannot break it out first by intefaces. I.e.
IDefactor
::Defacate()
IUrinator
::Urinate()
IBurper
::Burp()
Now we could build a class that implements all three... or only a few...
in to a collection of base classes that our "animals"... (Ahh we can use
both types of inheritance, kinda sounds like ADO.NET doesn't it =) DataRow
which is abstract (mustinherit) is an implementation of IList, ITypedList,
and IBindingList...
So to answer your question, you can build a build a base type, but you don't
have to use that base type to do your cross reference calls (remember that
implementation gets pushed up through the heirarchy as well) so your base
class that implements IUrinator and then something inherits your base
class... that new class also inherits IUrinator, so we can directly cast to
IUrinator.. Thats if the only thing you care about is making your animal
urniate, not how... just the fact it does.
I'm just trying to get Craig to think about alternatives that might not
have such a "permanent" impact on his code/architecture.
Exactly... my whole point is (as many will agree) inheritance is a
wonderful thing, however, it does take careful planning and management (as
most software does). So your point is valid there, your explanation was a
little off to why though. =)
Take care,
CJ
P.S. This is a fun place to be, don't get discouraged by doing anything
wrong... Hell, if I had a nickle for everythign I ever said wrong.. I'd
have a ****load of nickles...
=)
Andrew J. Marshall MCP (Visual Basic) Fairfax, VA
p.s. Offense only partly taken - given that this is a public forum, you could (should?) have said "This seems like a radical comment. Could you please explain in more detail?" That said, it was still funny as hell!
"CJ Taylor" <no****@blowgoats.com> wrote in message news:10*************@corp.supernews.com... Not trying to offend you or anything... just letting you know your
telling people the wrong things...
I'm glad you contribute... but, this is one of those times you were
just flat out wrong.. I'm wrong too (alot) and Cor/Herfried let me know.. or Peter Huang, but he doesn't count.
-CJ
"Andrew J. Marshall" <An*************@ObjectVision.netANTISPAMDEVICE> wrote in message news:%2***************@TK2MSFTNGP12.phx.gbl... LOL as well!!!
I'm just trying to impress an obvious beginner that inheritance isn't always the right thing to do. In fact it's the wrong thing to do.
Just because my implementations of Moose and Pig share 80% of the same functionality (namely Burp, Defecate and Urinate), doesn't mean I
should create a BurperDefecaterAndUrinator class/interface for them to inherit/implement.
That's what the hell I'm talking about, BABY! 8-)
Andrew J. Marshall MCP (Visual Basic) Fairfax, VA
"Robin Tucker" <id*************************@reallyidont.com> wrote in message news:c1*******************@news.demon.co.uk... > Lol - > > "CJ Taylor" <no****@blowgoats.com> wrote in message > news:10*************@corp.supernews.com... > > > > "Andrew J. Marshall" <An*************@ObjectVision.netANTISPAMDEVICE> > wrote > > in message news:uR****************@TK2MSFTNGP10.phx.gbl... > > > Craig, > > > > > > BEWARE!!! > > > > > > You could go the base class/interface route, but is that the "correct" > > > architectural decision. Are these two classes REALLY two
subtypes of > > > another, more generic thing (inheritance)? Or do they both
conform the > > same > > > contract (interfaces)? > > > > > > Instead, you could create some sort of observer/inspector class that > knows > > > how get the required information from your two classes. This
keeps your > > > classes pure if inheritance/interface implementation it not
called for. > > > > > > > What the hell are you talking about? > > > > > Just a thought, > > > Andrew J. Marshall > > > MCP (Visual Basic) > > > Fairfax, VA > > > > > > "Craig Buchanan" <so*****@somewhere.com> wrote in message > > > news:eQ****************@TK2MSFTNGP11.phx.gbl... > > > > If I have two custom vb.net classes, where 80% of the
properties are > > alike > > > > and there is one method with a matching signature, can i cast between > > one > > > > and the other? do i need to have each class implement a
common > > interface? > > > > > > > > thanks, > > > > > > > > craig buchanan > > > > > > > > > > > > > > > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alberto Giménez |
last post by:
Hi, I've seen some object oriented programming bits out there and i'm
not sure if they're legal. For example:
struct Object {
int field1;
int...
|
by: Jack MacRank |
last post by:
Hello,
I'm coding a webform application in C# (ASP.NET 1.1 SP1 with VS.NET 2003 Pro
on WinXP SP2 using IIS 5.1).
I created a seperate "data"...
|
by: Hazz |
last post by:
In this sample code of ownerdraw drawmode, why does the '(ComboBox) sender'
line of code need to be there in this event handler?
Isn't cboFont...
|
by: mra |
last post by:
I want to cast an object that I have created from a typename to the
corresponding type. Can anycone tell me how to do this?
Example:
//Here,...
|
by: Nick Flandry |
last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my
development environment (Win2K server running IIS 5) and a...
|
by: Jeremy Chapman |
last post by:
I want to access the viewstate of a page object from outside of the class
(in a helper class), so I made a class inherited from Page, and exposed a...
|
by: Belebele |
last post by:
Suppose that a class A depends on class B because an object of class B
is passed into A's constructor. See below:
class B { ... };
class A {...
|
by: Pieter |
last post by:
Hi,
I'm using NHibernate 1.2 (CR1), and I'm using a custom list (inherited from
BindingList(Of T) ) for all my lists.
The NHibernate...
|
by: =?Utf-8?B?U2NvdHQ=?= |
last post by:
Hello,
Using VS2008 in a C# web service application, a class has been created that
inherits from the ConfigurationSelection. This class file has...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...
| |