Design Patterns - Inheritance - Do All Properties In The Derived Classes Have To Be Declared In The Base Class

Aug 8, 2011

Background:I have a base class and several inherited derived classes. The derived classes don't always need to have the same properties. If any properties are shared among the derived classes, those properties would live at the base class level ('Contents', for example).Similarly, GoodDocument below has 'GoodThings' but would not want/need to have 'BadThings'.I want to treat instances of both 'GoodDocument' and 'BadDocument' as type 'Document'

public mustinherit class Document
public property Contents as string
public sub new()...

[code]....

View 3 Replies


ADVERTISEMENT

[2008] Base Class Inherited By 2 Derived Classes

Jan 30, 2009

i've finally got round to learning about classes and inheritance, but i'm not sure how to proceed. i have a base class Employee, which is inherited by 2 derived classes. how do i use the same Employee class in both derived classes? obviously if i write a sub new for both of them + declare a new Employee class, they won't be using the same class. heres my Employee class:

[Code]....

View 7 Replies

How Variables Declared With Protected Access In A Base Class Are Used To Implement Inheritance

Jul 29, 2010

how variables declared with protected access in a base class are used to implement inheritance.

View 1 Replies

Derived Classes Cannot Raise Base Classes

Jul 10, 2009

I m trying to raise Click event of Textbox explictly but I m getting "Derived classes cannot raise base classes" error.[code]....

View 1 Replies

Flattening An Object Hierarchy Using A Shim Class - Initializing Derived Object Properties From The Base Object?

Jul 10, 2010

I am somewhat new to object oriented programming and am attempting to flatten a Linq object hierarchy by using a shim class.how to initalize a derived class with property values from a base class?I have two objects, a base object with about 100 properties, and a derived object which inherits from the base object and adds a few additional properties beyond those of the base object. My simple constructor creates the derived object, but I am looking for a way to initialize the derived object properties with values from the base object.Right now I am using reflection to iterate over the properties individually and I suspect there may be a better way. The following example shows my shim class constructor for the derived class, and two properties:

newProperty1 - a new string property of the derived class

flattenedProperty2 - a new string property of the derived class, copied from a 2nd-level object of the base class

Code example:

Public Class derivedObj
Inherits baseObj
Private _newProperty1 As String[code].......

Is this the correct constructor approach to flatten the object hierarchy using a shim class? My second question relates to initialization of properties in the derived class. The constructor above creates the derived object, but what is the best way to initialize the derived object properties with values from the base object? The following code uses reflection to iterate over the properties individually, but I suspect there may be a better way.

Code example:

' property names are in the string array fieldNames

'baseObjQuery is an ienumerable of baseObj

'derivedObjList is a list of derivedObj[code].....

Is there a simple way to initialize values for the properties in the derived object based upon the values of the common properties in the base object?

View 7 Replies

Create A Derived Class, And Identify The Inheritance?

May 8, 2010

The test is base on Visual Basic inheritance, need to create a derived class, and identify the inheritance.

View 5 Replies

Form Inheritance - Error1Base Class 'MenuStrip' Specified For Class 'Lesson2' Cannot Be Different From The Base Class

Apr 15, 2010

I have put this code in the global form Inherits System.Windows.Forms.Form. And then in the form that will inherit this from the global Inherits MenuStrip. "MenuStrip" is what the global form is called. But keep getting this error: Error1Base class 'MenuStrip' specified for class 'Lesson2' cannot be different from the base class 'System.Windows.Forms.Form' of one of its other partial types.

View 5 Replies

.net - Suppress A Property Or Method From A Base-class In A Derived Class?

Apr 7, 2011

Supose a base class

Public Class airplane
Private var_num_seats As Integer
Private var_num_engines As Integer

[code]....

Obviously, I don't wish that the class Glider has the method "start_engines" neither the property "num_engines". Otherwise, other child classes may have. How can I supress these property and method in child class, not just ignoring (if I can)?

View 2 Replies

Access The Base Class Inside A Derived Class?

Oct 22, 2010

How do I access the base class inside a derived class?

View 1 Replies

VS 2008 Base/Derived Class?

Jan 17, 2010

Trying to implement some sort of commit/rollback functionality in my base objects. I have it working with some help from google. However, I have a question My Base Class has a BeginEdit as shown below -

[Code]...

Now, what I'm confused about is if I create another class, Class1, that inherits the base class. I add some properties such as Name, Age, Location, etc. to Class1.When I do Class1.BeginEdit, wouldn't "Me.memberwiseclone" make a copy of Class1, then CType try to cast it from Class1 to the BaseObject class? How does that work if Class1 has additional properties like the Name, Age..blah blah? Where do those gets stored in the Base class? I'm having a hard time wrapping my head around the concept...

View 3 Replies

Hide A Derived Method Of Base Class?

Sep 10, 2009

I would like to inherit from the Data.DataColumn in order to produce a DataTextColumn. That means that in the derived class, I dont want to see the non-applicable AutoIncrement property and the like - all I want to see are properties that apply to string types.[code]...

View 5 Replies

VS 2008 Same Interface, Base And Derived Class?

May 11, 2012

I'm struggling here.. I know I can disable the warning manually. However I'm not sure if this would be the right way to go about this.

Here's my interface..vbnet Public Interface IPopulatingClassBase Property Identity() As Int64 ReadOnly Property Dirty() As Boolean Sub Populate_Class(ByVal RecordID As Int64) Sub Save_Class() Sub Reset_Class()End Interface

[Code]...

PS In my example think of it as classes that populate with data from a database. The parent class would be an organization, and the derived class a location. Both populate and have similar functionality. The only difference is locations are an entity of an organization(the data record for a location constraints it to an organization) upon loading location data I also populate the organization class. This is a real example of what my project does.. so having said I just want to know how I can get around this warning, and if not would it have any consequences if I left it as-is.

View 6 Replies

Using Reflection To Attach / Detach Handler Of Base Event In Derived Class

Dec 13, 2009

I am just curious, if there is some way to attach handler to my derived classes base event, if I know EventInfo and I have Delegate to handler function. I have tried MyEvent.AddHandler(CType(Me, BaseClassType), MyDelegate) already, but no positive result at all. Consider being in need of attaching handler to custom event at runtime, while derived class possibly shadows this event.

View 2 Replies

[02/03] Base Class Called PageBase And Then A Derived Class TestPage That Inherits From PageBase

Feb 4, 2009

I have a base class called PageBase and then a derived class TestPage that inherits from PageBase. In PageBase I have overridden the OnInit() and when it is called and I inspect the value of 'Me', it is of the type of the derived class and not the base class. My question is how does inheritance really work? For instance, when instantiating TestPage does an instance of PageBase get created too?

Here is my code;

Partial Public Class TestPage
Inherits PageBase

Public Sub New()

[code]...

View 7 Replies

VS 2010 : UserControl MouseEnter/Leave Events Aren't Firing - Cannot Raise Base Event From Derived Class

Feb 18, 2011

When i use my UserControl in a project my Mouse Enter & Leave events aren't firing, i assume i fix this with a raiseevents in my usercontrol. However when i try to do this it says something about "cannot raise base event from derived class".

View 7 Replies

Use Derived Class Shared Variables In Shared Methods Of Base Class?

Jun 4, 2010

I am trying to add shared members in derived classes and use that values in base classes...

I have base

class DBLayer
public shared function GetDetail(byval UIN as integer)
dim StrSql = string.format("select * from {0} where uin = {1}", tablename, uin)
end function
end class

[Code]..

currently there is error using the tablename variable of derived class in base class but i want to use it i dun know other techniques if other solutions are better then u can post it or u can say how can i make it work? confused...

View 2 Replies

Inheritance (Private Overrides Function) - Create A Class And All Other Classes Inherit From It And Modify It A Bit

Oct 15, 2011

I am cleaning up some code and I have multiple classes that are 99% exactly the same. So my understanding is that my options are...

1. Create a class and all other classes inherit from it and modify it a bit

2. Create an abstract class and all classes inherit from it and modify a bit ** I took this route

3. Create an interface and all classes Implement that interface.

Here is my 'original' class below (the one that all of them look 99% identical). This class is used in an arraylist so I have a listing of all my images from a folder I have searched.

[Code]...

View 10 Replies

.net - Can A Generic Version Of A Derived Class Override A Base Method Using The Generic Type

Apr 13, 2012

Consider:

Public MustInherit Class Column
Public ReadOnly Property ReturnSomethingUseful() As Object
Get
'return something useful

[code]....

But this gives the following error:

Public Overrides Function ParseValue(sValue As String) As Boolean'
cannot override 'Public Overridable Function ParseValue(sValue As String) As Object'
because they differ by their return types.

I accept that you can't do this, but I'd like to be able to preserve the semantics of what I'm. trying to do, which is to have an untyped version that deals with Object, but a typed version in derived classes that knows about the specific type T.

View 2 Replies

Can't Inherit Shared Properties From A Base Class In A Child Class?

Dec 29, 2010

This is another one of my "I think it's not possible but I need confirmation" questions.I have a base class for a bunch of child classes. Right now, this base class has a few common properties the children use, like Name. The base is an abstract class (MustInherit)Technically, this means that everytime a child class is instantiated, it lugs around, in memory, its own copy of Name. The thing is, Name is going to be a fixed value for all instances of a given child. I.e., Child1.Name will return "child_object1", and Child2.Name will return "child_object2".

View 1 Replies

VS2008/VB: Moving Subclass VB Code To Inherited Base Class - Where Should Variables/objects Be Declared

Jun 3, 2009

In re-engineering a windows forms application, I find that a lot of code-behind in the various form classes is duplicative and I'm trying to centralize as many procedures as possible into a base class which can be inherited and used by the subclassed forms.

This process seems to be going well and is making the code in my subclasses much simpler and hopefully easier to maintain, but I'm not sure where to draw the line between leaving code in the subclasses and engineering for generic resusability and moving it to the base class.

Specifically, in some subclasses I have code which manipulates variables and objects specific to the subclass, and although I could move the code-behind into the base class, the base class code references specific objects which are needed to compile. For example, each subclass manipulates a databound datagridview and form detail controls which allows the user to select between multi-record and detailed single-record views of a datatable.

In Visual Basic 2008 do I need to declare dummy data objects in the base class so that the base class will compile? Or is there a way to indicate that the data objects will be provided by the subclass?

View 13 Replies

Base Class With Shared Fields And Functions Good Design ?

Apr 22, 2010

I've got a BaseDataClass with shared fields and functions

CODE:

I have several classes that derive from this base class. The derived classes have all Shared functions that can be called directly from the BLL with no instantiation. The functions in these derived classes call the base Init(), call their specific stored procs, call the base CleanAll() and then return the results.

So if I have 5 derived classes with 10 functions each, totaling 50 possible function calls, since they are all Shared, the CLR only calls one at a time, right? All calls are queued to wait until each Shared function completes.

Is there a better design with having Shared functions in your DAL and still have base class functions? Or since I have a base class, is it better to move towards instance methods within the DAL?

View 1 Replies

Assigning Results To Base Class Properties

Apr 26, 2009

I have a base class where amongst other code I have declared 2 properties. In my derived class, I get data from the DB and assign the results to the base class properties. This is so when I go back to the base class code, I can access the property values. It allows me to set the values in the derived class but once I go back to the Base class, the values don't exist.

Snippets of code sample:
base class:
Public Class ServiceProcessor
Private mSalesOrderID As Integer = 0
Private mName As String = ""
Friend Property SalesOrderID() As Integer
[Code] .....

View 6 Replies

Class Hierarchy - Data Design In A RPG Game Where Classes Overlap?

Aug 19, 2010

This is a followup to the question I asked here:

[URL]

I understand the answer in the post above, which is absolutely amazing, by the way. It's about implementing interfaces with a class. However, what if a class needs to share features with another class?Yes, that class can an Interface. However, let's use this sample definition.

[code]...

Or, in other words:An equippable item can perform acts outside of its typical usage of a shield or weapon. But not all items can act as a sheid or weapon.I mean, I could create a class that implements IWeapon, IShield, IMagic, IUseableItem, etc. But there should be a better way than returning NULL when those interfaces are called.

View 2 Replies

Best Pratice In Inheritance - Three Classes Employee, Manager And Salesman. Manager And Salesman Classes Inherits Employee Class

Jul 27, 2010

I have three classes Employee, Manager and Salesman. Manager and Salesman classes inherits Employee class.

Employee :

Public MustInherit Class Employee
' Field data.
Protected empName As String
Protected empID As Integer
Protected currPay As Single

[CODE]...

Manager :

Public Class Manager
Inherits Employee

[CODE]...

Salesman :

Public Class Salesman
Inherits Employee

[CODE]...

Now I have created a object of salesman and manager using the following code:

Dim objSalesMan as Employee=new Salesman("xyz",1,2000,5000)
Dim objManager as Employee=new Manager("abx",2,5000,"production")

Is this a good programming pratice or should I use:

Dim objSalesMan as new Salesman("xyz",1,2000,5000)
Dim objManager as new Manager("abx",2,5000,"production")

View 6 Replies

Instance A Class, Based On Other Classes, Add New Properties?

May 26, 2009

You know how everyone says "C++ is like C with classes"?How similar is it to .NET classes? instance a class, based on other classes, add new properties, override existing properties, etc?Are the variables strongly-typed and declared before they are used? Or is it a Duck-Typing language like Python?

Also, does it have its own Garbage Collector that disposes of objects when the pointer exits their scope,or do you have to manually clear and get rid of them when you finish with them? What's the difference between native C++, and the "managed C++" in Visual Studio? Because I'd prefer to use native code if its not too much harder. for the sake of all that is good and holy, don't use ACCESS, EXCEL, or a TEXT FILE as a database. If you want your program to use a "local database", without any of the hassle of setting up a MS SQL or MySQL server, just click this link: >>> SQLite <<< Seriously. This is for your own good.

View 3 Replies

Component Not Visible - 'owner' Conflicts With Property 'owner' In The Base Class 'Form' And Should Be Declared 'Shadows'

Oct 27, 2009

I placed this checkbox named owner on my form. When i build the project i got the error as
Quote: 'owner' conflicts with property 'owner' in the base class 'Form' and should be declared 'Shadows'

[Code]...

View 10 Replies

WithEvents Variable 'PreviousPage' Conflicts With Property 'PreviousPage' In The Base Class 'Page' And Should Be Declared 'Shadows'?

Feb 1, 2012

I am converting an application from vb.net 2003 to 2005. I got the following warning and need help how to resolve it. withEvents variable 'PreviousPage' conflicts with property 'PreviousPage' in the base class 'Page' and should be declared 'Shadows'

View 1 Replies

Design Patterns - Implement The IDisposable Interface With A Dispose?

Apr 21, 2009

Recently I needed to compare a suggested pattern for IDisposable and object finalization with the auto-generated one we which VS2005/VB.NET provide. We have used the auto-generated one a fair bit, but after looking it the two side by side I had a number of questions about the VB.NET implementation..

[Code]...

Overall I am confused by the supposed added value of having an extended code-path that executes when Dispose() is called explicitly(as opposed to having a common path that is executed regardless of whether or not Dispose() was called explicitly). how it does anything other than delay the actual release of managed resources if Dispose() isn't called directly. In essence it seems to only work to make the managed resources unreachable in the object graph, orphaning them until the 2nd GC run rather than freeing them at a point where they are known to be no longer needed.

View 3 Replies

Warning : "Function 'Show' Shadows An Overloadable Member Declared In The Base Class 'Form'"

Jan 26, 2011

Yesterday I started my first DLL project which is for ArabicMessageBox that will allow arabic programmers to display there message in totally Arabic message.My project contain one Form only, and the basic code that I use is:

Public Overridable Function Show(ByVal APrompt As String) As MsgBoxResult
mLoad(APrompt, MsgBoxStyle.OkOnly, "")
Me.ShowDialog()

[code]....

View 9 Replies

Inheritance A Classic React Class Into A User Control To Add The Hight And Width Properties To The Control?

Feb 28, 2011

I tried it and get an error but maybe I'm tring the wrong way. Can a usercontrol inherate an application defined class ie.. could you inheritance a classic rect class into a user control to add the hight and width properties to the control without having to do all the coding all over again? Currently I just declair a private instance of the class within the control and then encapsalate. It would be nice if I could just inherit all the functionality of my classes into controls designed to implament the classes.

View 1 Replies







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