473,511 Members | 15,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OOP Inheritance Question

Hi

This question is based around VB.Net but could probably apply to c# or any
OOP language as well.

We found some old (ish) code in our code base and have been unable to decide
if it is pure genius or something else besides. As it stands we're leaning
towards something else but would welcome some outside comments.

The situation is.

We have a base class:

Public Class NewBase

Private _strName as String

Public Sub New
<constructor code here>
End Sub

Public ReadOnly Property Name() as String
Get
Return _strName
End Get
End Property

End Class

and we have an Interface:

Public Interface INewInterface

Public Readonly Property Name() as String

End Interface

What we have observed is a class that implements the interface and inherits
from the base class like so:

Public Class NewClass: Inherits NewBase
Implements INewInterface

Public Sub New()
MyBase.New()
End Sub

Public Shadows ReadOnly Property Name() as String Implements
INewInterface.Name
Get
Return MyBase.Name
End Get
End Property

End Class

The actual code found is more extensive but the example above indicates the
sort of code that has been written. As I said most of us here think that this
is rubbish, and fundementally wrong and amounts to nothing more then double
concentrated boiler-plating but there's always that nagging feeling that it
may just be genius and felt that an outside opinion would be helpful.

Just for the fun of it we have named it InterBase Inheritance :-)

Sorry if this has been posted in the wrong group.

cheers

Rupert



Jul 31 '07 #1
3 1298
* Rupert Taylor wrote, On 31-7-2007 18:36:
Hi

This question is based around VB.Net but could probably apply to c# or any
OOP language as well.

We found some old (ish) code in our code base and have been unable to decide
if it is pure genius or something else besides. As it stands we're leaning
towards something else but would welcome some outside comments.

The situation is.

We have a base class:

Public Class NewBase

Private _strName as String

Public Sub New
<constructor code here>
End Sub

Public ReadOnly Property Name() as String
Get
Return _strName
End Get
End Property

End Class

and we have an Interface:

Public Interface INewInterface

Public Readonly Property Name() as String

End Interface

What we have observed is a class that implements the interface and inherits
from the base class like so:

Public Class NewClass: Inherits NewBase
Implements INewInterface

Public Sub New()
MyBase.New()
End Sub

Public Shadows ReadOnly Property Name() as String Implements
INewInterface.Name
Get
Return MyBase.Name
End Get
End Property

End Class

The actual code found is more extensive but the example above indicates the
sort of code that has been written. As I said most of us here think that this
is rubbish, and fundementally wrong and amounts to nothing more then double
concentrated boiler-plating but there's always that nagging feeling that it
may just be genius and felt that an outside opinion would be helpful.
I'd call it rubbish as well. Just let Newbase inherit from INewInterface
and you're done. Unless there are things you later plan to add to
NewInterface that should never get into NewBase you could separate them.
My guess is that the previous code owner doesn't really understand how
inheritance works.

For me any shadows in vb or new in a method declaration automatically
stinks :) (unless it's to work with a component that isn't under your
control).

Jesse
Jul 31 '07 #2
Looks as if he/she is testing or demoing the new/shadows feature.

"Jesse Houwing" <je***********@nospam-sogeti.nlwrote in message
news:eB**************@TK2MSFTNGP06.phx.gbl...
>* Rupert Taylor wrote, On 31-7-2007 18:36:
>Hi

This question is based around VB.Net but could probably apply to c# or
any OOP language as well.

We found some old (ish) code in our code base and have been unable to
decide if it is pure genius or something else besides. As it stands we're
leaning towards something else but would welcome some outside comments.

The situation is.

We have a base class:

Public Class NewBase

Private _strName as String

Public Sub New
<constructor code here>
End Sub

Public ReadOnly Property Name() as String
Get
Return _strName
End Get
End Property

End Class

and we have an Interface:

Public Interface INewInterface

Public Readonly Property Name() as String

End Interface

What we have observed is a class that implements the interface and
inherits from the base class like so:

Public Class NewClass: Inherits NewBase
Implements INewInterface

Public Sub New()
MyBase.New()
End Sub

Public Shadows ReadOnly Property Name() as String Implements
INewInterface.Name
Get
Return MyBase.Name
End Get
End Property

End Class

The actual code found is more extensive but the example above indicates
the sort of code that has been written. As I said most of us here think
that this is rubbish, and fundementally wrong and amounts to nothing more
then double concentrated boiler-plating but there's always that nagging
feeling that it may just be genius and felt that an outside opinion would
be helpful.

I'd call it rubbish as well. Just let Newbase inherit from INewInterface
and you're done. Unless there are things you later plan to add to
NewInterface that should never get into NewBase you could separate them.
My guess is that the previous code owner doesn't really understand how
inheritance works.

For me any shadows in vb or new in a method declaration automatically
stinks :) (unless it's to work with a component that isn't under your
control).

Jesse

Jul 31 '07 #3
On Jul 31, 5:36 pm, Rupert Taylor
<RupertTay...@discussions.microsoft.comwrote:
Hi
We found some old (ish) code in our code base and have been unable to decide
if it is pure genius or something else besides.

At first glance I'd pretty much have to go with the other comments
that it seems to be an egregious example of using the shadows/new
facility but it hard to be definitive when examining just these
(simplified) classes in isolation.
Whether or not this setup is good/useful depends upon the other
classes in the system.

NewBase
^
|
NewClass implements INewInterface
Do you have any other classes inheriting from Base which do not
implement INewInterface

e.g.

NewBase
^
|
SomeOtherClass
SomeOtherClass inherits the Name property but as it does not implement
INewInterface it cannot be access through INewInterface.
For the above example it seems strange to have the INewInterface only
on the dervied class when the base class already implements ALL of the
INewInterface. As mentioned, just place it on the NewBase class.

However, I can see situations where we want an interface on the
derived class which implements lots of things, some of which are
already defined in the base class.

e.g.

INewInterface
Name
Address
Age
Height
In VB.Net we would need to shadow the Name property because it already
exists in the base class (AFAIK, in C# we do not need to 'new' the
property as implicit implementation of the interface will pick up the
Name definition from the base class) but we need to place this
interface on the NewClass because the base class does not have and
Address, Age or Height)

HTH,
Alan.
Aug 2 '07 #4

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

Similar topics

1
3723
by: KK | last post by:
Windows Forms Inheritance, Incomplete? I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the...
2
2173
by: KK | last post by:
** Posting it here cause after couple of days no body responded.** I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can...
4
12799
by: Dave Theese | last post by:
Hello all, The example below demonstrates proper conformance to the C++ standard. However, I'm having a hard time getting my brain around which language rules make this proper... The error...
8
7816
by: __PPS__ | last post by:
Hello everybody, today I had another quiz question "if class X is privately derived from base class Y what is the scope of the public, protected, private members of Y will be in class X" By...
22
23319
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
45
6310
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
6
2084
by: VR | last post by:
Hi, I read about Master Pages in ASP.Net 2.0 and after implementing some WinForms Visual Inheritance I tryed it with WebForms (let's say .aspx pages, my MasterPage does not have a form tag itself...
5
2449
by: Noah Roberts | last post by:
Is there anything that says that if you virtually inherit from one class you have to virtually inherit from anything you inherit from?
3
1807
by: RSH | last post by:
I have a simple question regarding inheritance in a web form. I have a DropDownList in an aspx form. It is called DropDownList1 I have a class that will be overriding the render event so I...
8
328
by: RSH | last post by:
Hi, I am working on some general OOP constructs and I was wondering if I could get some guidance. I have an instance where I have a Base Abstract Class, and 4 Derived classes. I now need to...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7418
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...
0
7508
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...
0
5662
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,...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3222
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...
0
1572
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 ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
446
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...

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.