VS 2008 Inheritance Question (or Maybe Not)?

Dec 15, 2009

I've not played with inheritance myself much as I've never really had a need to, but now I have a situation which to me seems the ideal time to learn. I'll explain:

This is a WPF application but that shouldnt make any difference to this question. Basically, I have asearch window that retrieves data from a database - I want this one search window to be able to retrieve any item (business object might be a better word than item) from the database and display the relevant data, rather than having a separate window for each 'type' of item in my program. So I have got 3 classes at the moment, ComputerAudit, ConnectionAudit, and SoftwareAudit and I want my one search window to be able to display any of these items in the listbox. Obviously there would only be one type of item displayed at once, so there wouldnt be a computeraudit item and a connectionaudit item displayed in the list at the same time, but there could be several computeraudit items displayed.

So I thought I could create a base class just named Audit and have those 3 classes I mentioned inherit from that, then I can specify the arguments to methods I am using as just being of type Audit (rather than using a specific type like ComputerAudit or SoftwareAudit) because then I should be able to pass around any of these items which inherit from Audit right? Well that doesnt seem to be the case so I'm wondering if I have misunderstood inheritance.

The problem I'm having specifically is that I have some methods which need to be able to accept any of my Audit subclasses but if I specify a generic List(Of Audit) then it wont let me pass in a List(Of ComputerAudit) for example. Is this because I'm using a List or am I just doing something fundamentally wrong?

EDIT: Found this page which confirms my suspicions that this is more to do with the List than general inheritance:[URL]...

View 39 Replies


ADVERTISEMENT

VS 2008 Inheritance And Events

Jul 8, 2009

I have a base object, with a event that can be triggered by multiple methods.Then I created a child object that inherits that base object. I want to be able to trigger that event in the new object; but I can't use RaiseEvent to raise a base-object's event.To get around this, I created a small method in the base object that takes the argument for the event and I just use it to trigger the event. Is this the proper way to handle this situation? Similarly, I could Shadow the event with a duplicate one in the child object.Is there a standard way to handle events across inheritance?

View 2 Replies

Inheritance And Entity Classes In VB 2008?

Jun 27, 2011

I am having trouble getting inheritance to work with the VB 2008 Express entity classes. I am a beginner with VB.Net and self-taught in VB6.0.I am able to pull data from an SQL Server data base into my application using the O/R designer. The data can be successfully queried using LINQ to SQL, either returning a single record, or multiple records or an entire table as a collection of the enty class type (so the problem is not with LINQ queries).

View 2 Replies

VS 2008 Object Inheritance And Casting

Mar 23, 2011

I have two custom objects.On of them inherits the other one, appends few more properties and methods, ovverides some other.When I try to cast the Parnet Object to Child I receive an error that it could`nt be done.

View 1 Replies

VS 2008 : Inheritance And Copy/use Of Member Instances?

Jul 31, 2010

If I declare and instantiate an instance of class B within class A, how do I make instances of class A member objects/variables accessible from class B?

View 11 Replies

VS 2008 DGV Inheritance - Create The Control In Another Project To Build The Dll

Nov 26, 2009

In my application i will use a customized datagridview for all the application, so instead of adding the normal datagridview and changing the properties, i created an user control and changed the inherited to datagridview... This have a problem i can't use the drag and drop...

[Code]...

View 4 Replies

VS 2008 Class Within A Class (Inheritance)?

Jan 11, 2010

i have a class call it clsFamily this class contains properties that make up a family object. This class works fine with no issues. Now i need a new class (called MyAccount) which contains 3 properties, an ID a user name and a clsFamily object. I have declared both classes as Friend from within my globals Module and define the clsFamily as family, however when i try to put this type within my 2nd class i get an error "Type 'family' is not defined" what am i doing wrong? i know i could get it to work fine by adding the ID and User Name properties to the clsFamily object but i need to define this as a new type of object as the ID and User name are not normally part of this class.

View 12 Replies

How To Apply Inheritance

Apr 22, 2012

i am just trying to apply inheritance ..Below is my Code ... on which i am not getting the output on my Text_Box ... when in write it in a Child Class

Imports System
Imports System.Windows
Imports System.Windows.Forms

[code]....

View 4 Replies

Oop - Inheritance And Interfaces ?

Jul 14, 2011

Has someone a hint what I'm doing wrong in VB.Net?

Module Module1

Interface ISearch(Of T As ISearchResult)
Function ids() As List(Of T)
End Interface

[CODE]...

The third cast isn't working. Why? did I miss a oop lesson?

View 2 Replies

Why Only One Parent In Inheritance

Mar 2, 2011

What's the choice design that microsoft do that? Of course, as of me, I don't use inheritance a lot, or at all.

View 14 Replies

.net - Inheritance And Collection Of Objects?

Oct 21, 2011

we have 3 classes:Class S, class A, class B / A and B inherits S.A has a property A1 and B has a property B1.we also have a collection of objects that has A and B objects.ex.

Dim c as Collection = new Collection
c.add(new A)
c.add(new B)

Now we want to make a general object that will read from the collection.

ex .
Dim obj as S

how can we cast obj in order to see properties A1 or B1 according to the class;

View 1 Replies

.net - Inheritance Works For First Descendant But Not Next?

Apr 20, 2011

Form1
Public Class Form1
Private Sub But_Bell_Click(sender As System.Object, e As System.EventArgs) Handles But_Bell.Click
MessageBox.Show("Ding a ling")
End Sub

[code]....

Where has the whistle button gone? The class part of the inheritance has works because you can access it via code.

View 1 Replies

.NET Constructor With Parameters And Inheritance?

Jun 29, 2010

Why VB.NET (vs C#) does not "inherit" the constructors with parameters?

Public Class StopLine
Inherits Microsoft.VisualBasic.PowerPacks.LineShape
Public Sub New()
MyBase.New()

[code]....

View 1 Replies

.net Multiple Inheritance In An Interface?

Apr 15, 2011

I'm facing a problem regarding multiple inheritance in VB.net:As far as I know VB.net does not support multiple inheritance in general but you can reach a kind of multiple inheritance by working with interfaces (using "Implements" instead of "Inherits"):

Public Class ClassName
Implements BaseInterface1, BaseInterface2
End Class

That works fine for classes but I'd like to have an interface inheriting some base interfaces. Something like that:

[Code]...

View 3 Replies

C# - Appropriate To Use Generics Versus Inheritance?

Apr 28, 2009

What are the situations and their associated benefits of using Generics over Inheritance and vice-versa, and how should they be best combined?I'm going to try to state the motivation for this question as best I can:I have a class as shown below:

[Code]...

Now suppose I have a repository that takes an InformationReturn argument, that has to strore different fields in a DB depending on the type of Info object T is. Is it better to create different repositories each for the type T is; one repository that uses reflection to determine the type; or is there a better way using inheritance capabilities over/with generics?

View 6 Replies

C# - Serialization Across Projects With Inheritance?

Jul 19, 2010

I have a base class ("MyBaseClass") in a project called "BaseFramework" which is included in several solutions within the company. There are several derived class's in various projects throughout the company that inherit from "MyBaseClass". If I then create a List and add derived class's to it, it will not serialize. I realise that if I were attempting to serialize this list, and the base class and derived class were in the same project, I could simply apply the "XmlInclude" attribute to the base class and include all of the derived class's. This is however not possible across projects, because that would require a circular dependency.

View 1 Replies

Constructor With Parameters And Inheritance?

Jun 23, 2011

I searched quickly and not find an explicit answer at the following question:Why VB.NET (vs C#) does not "inherit" the constructors with parameters?

Public Class StopLine
Inherits Microsoft.VisualBasic.PowerPacks.LineShape
Public Sub New()

[code].....

View 2 Replies

Convert Inheritance With Interface From C# To VB?

Jan 6, 2012

How can I convert following code to VB.NET?

class A
{
public int NumberA { get; set; }
}

[code]....

In VB.NET there is problem with Implements keyword after property declaration. So I need to do something like this:

Class B
Inherits A
Implements IC

[code]....

But there is duplicit misleading property NumberA1.

View 3 Replies

DataBinding Inheritance And Typeconverters?

Jan 19, 2010

I have the following code; now i set a propertygrid.selectedobject to the Square object, and start changing the Squares properties. If i change the [Position.x] or [position.y] values in the propertygrid the [Position] and [center] properties update correctly, however when i change the [Center] property, neither [Position] or [Position.x] or [Position.y] update. Is there something else i must do to get this to work both ways. Maybe something is lacking in PointFConverter?

Imports System
Imports System.Collections
Imports System.Drawing

[code]....

View 2 Replies

FAKE Inheritance In C# / Program?

Dec 14, 2011

Suppose I want to inherit from System.Data.SqlClient.SqlTransaction which is sealed. Supose I want to just put a wrapper around SqlTransaction and always use MyTransaction instead of SqlTransaction. Is there a way I could potentially cast MyTransaction to SqlTransaction using an Implicit/Widening operator?

View 8 Replies

Generic Collections And Inheritance?

Aug 24, 2009

I have a parent class and many children class, right now it look like this:

Public Class Parent
Public Property ID as String
End Class

[Code].....

What I need is a strongly type list List(Of Child) that Inherits from ListOfParent (I need the FindByID method) but I can't find the right syntax.

View 10 Replies

Get Around Lack Of Multiple Inheritance?

Nov 5, 2009

get around lack of multiple inheritance

View 2 Replies

Getting Around Lack Of Multiple Inheritance?

Aug 24, 2010

I am currently working on a framework for applications developed by my company, my boss wants to have a switchboard and a MenuStrip, where the entries and their actions are controlled by a database.

Now I've dealt with all the code to get them working. But the problem that I am facing is that I have duplicated code because each of the classes have the code that deals with ensuring the user has the right privileges and the code to deal with when a user clicks on an item.

Normally I would move this code out into a class and then have each of the classes inherit from the class, but because the switchboard already inherits from the Form class and the customised MenuStrip inherits from the MenuStrip class.After doing some Googling the only answer I have been able to find it using an interface for the functionality, which is obviously not exactly what I want.

Anyway I was just wondering whether any one had any suggestions on what I could do to deal with this problem, as I would like to avoid having duplicate code as much as possible.

View 2 Replies

Implement Without Multiple Inheritance?

Sep 1, 2011

I have a library of graphical controls used to display values from a remote device. The controls are typically graphical objects such as a digital meter, analog meter, vertical bar, etc. I first create these controls with a value property. The control will display the value property, e.g. the meter needle will move to the position representing the value.

The next thing I do is to create a new control that inherits the previous discussed control. The new control adds properties that allows the value to be set from values retreived through a communication component. My code that does this is 99% the same for all of the controls. Since I already inherit the graphical control, I can not inherit the class that retreives the values from the communication component.

[Code]....

View 5 Replies

Inheritance - Dependent Types In .NET?

Sep 14, 2011

I was wondering if it is possible to have dependent types in VB.Net 4, or alternatively, if it is possible to construct inherited objects based on the base class' constructor's parameter(s). For example,

[Code]...

View 1 Replies

Inheritance - Spot The With .Net Code?

Sep 12, 2010

I'm writing some code in VB.Net which I hope demonstrate to colleagues (not to say familiarise myself a little more) with various design patterns - and I'm having an issue with the FactoryMethod Pattern.

[Code]...

View 3 Replies

Inheritance Of List(of T) In A Class?

Dec 3, 2009

working on an implementation of a list control for a card game. The catch is the deck control object. I want it to be reusable for different types of cards, which is wheretuck since I seem to be having some issues.First: The basic card object

Public Class BaseCard
'Properties
Private _Id As Integer

[code]....

View 4 Replies

Non Visual Inheritance Of WinForms?

Sep 21, 2011

I have two Forms, which have similar Functionality (i.e. an amount of similar Controls) but complete different Layout. So the normal inheritedForm (which VS2010 provides) wont work here.

I have tried following:

Public Class BaseForm
Inherits System.Windows.Forms.Form
Friend WithEvents Button1 As System.Windows.Forms.Button

[Code].....

So it looks like, the Designer only tries to guess how the Form looks like by inspecting the top-most Class, without compiling the full inheritance-Tree...

View 1 Replies

Partial Inheritance For A Button?

Mar 16, 2010

I would like to create an user control that has a panel and a button. The user control should set font color, size, font type, and other properties but when I place the user control on a form I would like to be able to modify the text for the button.

View 5 Replies

VB Inheritance And Narrowing Conversions

Aug 6, 2009

I am rather new to OOP and I have, what may be, a simple question. I am developing an architecture for a project that includes some object inheritence trees. I have been running into a bunch of narrowing conversion issues (the old 'Unable to cast object of type x to x' error). I understand the limitations of narrowing conversions and why this error exists, but I'm not quite sure how to get around it architecturally. Here is an analogous problem to mine...

[Code]...

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved