How To Avoid Writing Common Code In Derived Class
Jun 28, 2010
I am trying to minimize my code writing. I have DBLayer base class that selects, inserts, updates and deletes records from database. I need only fieldlist and table name from each derived classes to perform the actions. I have defined static tablename, fieldnames in derived class. Currently I am defining next static functions in derived class for GeneralSelect [which selects all records], GeneralInsert[Which inserts a records], GeneralUpdate[Which updates records as per given id] and GeneralDelete[Which deletes a record of the given id]. The parameter and all functioning are same just the differece is the table name and fieldnames.
One DBLayer Class that performs database actions
Class DBLayer
Public shared function Query(byval SQL as string) as dataTable
[code]....
... same goes for all other table objects... If I have 20 database tables i have to write getdata method in all 20 class changing only the tablename so i would like to get ride of it. So in order to get ride of it what do i need to do?
View 1 Replies
ADVERTISEMENT
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
Oct 22, 2010
How do I access the base class inside a derived class?
View 1 Replies
Apr 20, 2011
I'm writing a set of unit tests for a large, complex class called ImageEditor from a piece of legacy code, where image processing and GUI functionality isn't strictly divided. One of the methods in the class, BaseImageChanged, seems to be concerned entirely with how images get displayed and should be disabled in my unit tests to avoid unnecessary complexity. The test project is in C#, and the original code is in VB; my idea was to create a Decorator for the class in C# and then hide the method behind an empty one that does nothing. However, when I try running the unit test, the VB code keeps referencing the old BaseImageChanged method as though the replacement didn't exist. Here's what I'm doing:
(VB class)
Public Class ImageEditor
...
[code].....
View 4 Replies
Oct 19, 2010
I have two classes, one derived from another.
Private Class clsVehicles
Public Make As String
Public Model As String
[Code]....
View 11 Replies
Mar 19, 2010
I use to set WithEvents variables to Nothing in Destuctor, because this will "Remove" all the Handlers associated with Handles keyword. Will this have the same effect for derivated classes?
[Code]...
View 1 Replies
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.
[Code]...
View 8 Replies
Jun 18, 2008
I have a derived DataTable[code]...
Overload resolution failed because no accessible LoadDataRow' can be called with these arguments.
View 15 Replies
Nov 3, 2010
I have a function that 2 derived classes use, but the third doesn't, would it make sense to just leave it in the base class, even though one of the 3 derived classes doesn't use it?The only way I could think of disallowing the third class is to basically create an intermediate class that is derived of the base, then the 2 that use the common function are derived off the second class.
Is it possible to prevent the 3rd class from using the function, while letting the two that are supposed to use it, use it?Does that just seem to go overboard, I mean as long as I don't "try" to call the function from the 3rd class, it shouldn't be a problem, I just was interested if there was a way to prevent it all together without a lot of hassle.
View 2 Replies
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
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
Oct 16, 2010
I am trying to make a program in Visual Basic 2008 Express edition which have a textbox where the user can write information to search for in a simple database stored in the program-code.
What I would like is that when the user types a word, a string variable connected to that textbox.text will be treated as a string. BUT if the user types a number in the textbox, the textbox.text will be treated as an integer (for example a "Double")
View 3 Replies
May 8, 2010
The test is base on Visual Basic inheritance, need to create a derived class, and identify the inheritance.
View 5 Replies
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
Dec 16, 2009
I have an interface (called IPersistentBusinessObject) with a required function that looks like this:
Function GetFields(ByVal fromDatabase As clsODBCDatabase) As enumSuccessFailure
In a class, I try to satify the requirement with the following:
Public Function GetFields(ByVal fromDatabase As clsDatabase) As enumSuccessFailure Implements IPersistentBusinessObject.GetFields
In this example, clsDatabase inherits from clsODBCDatabase. So I'd expect this to work since clsDatabase does everything clsODBCDatabase does and more. However, it does not work. The compiler complains that I haven't properly satisifed the interface requirements for GetFields. Can anyone tell me why this does not work?In slightly different but related example, I have an interface that requires a function called 'AddItem' as in:
Sub AddItem(ByVal objObject As IPersistentBusinessObject)
In my 'building' class, I attempt to satisfy this requirement using:
Public Sub AddItem(ByVal building As clsBuilding) Implements IPersistentBusinessCollection.AddItem
In this example, clsBuilding implements the interface IPersistentBusinessObject. So I'd expect this to work since clsBuilding satisfies the interface contract. However, it does not work. The compiler complains that I haven't properly satisifed the interface requirements for AddItem. why this does not work?
View 10 Replies
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
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
Apr 28, 2009
I have a Base Class, called primitive Graphics. derived from this class are several different types of graphics, squares, rectangles, lines, etc. I am storing those graphics in an object that inherits collectionbase. This causes a problem because I cannot access any of the members in the derived class when they are added to the collection. Here is the default property for my primitivecollection class
[Code]...
My current workaround is to just put all of the public members in the base class, however this is starting to look ugly as I add more derived classes that need members available to the derived class only
View 3 Replies
Aug 29, 2011
I was working on a custom button, in which I had to capture the event of the button, and depending on the certain conditions, either I'll block the event or pass it on the form containing my custom button.[code]Now, I do not have any idea how to block the event and not allow it to pass if the users opts for "No" in the given example.
View 1 Replies
Oct 8, 2010
Can we override a Public Shared method in derived class? If not why?
View 2 Replies
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
Jan 22, 2012
Wondering if it is possible. It works on the idea that all files share common code. The program would ideally analyse the source file and compare it to the reference files. It would then find common parts of the code and write it to a rebuild file. At the end the rebuild file and the reference files would then be able to rebuild the source file without it being present.
For Example.
source file code = xxyyzyzyxw
ref file 1 = xyxxzyzxwyy
ref file 2 = zxxwyzzywxx
The program would then analyse these files and make a rebuild file like the following
source(0,1) = ref1(2,3)
source(2,3) = ref1(10,11)
source(4,7) = ref2(5,6) + ref2(5,6)
source(8,9) = ref2(2,3)
Thus you would be able to build the source file using these instructions and the reference files.
View 1 Replies
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
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
Jan 22, 2010
I have some common code that I would like to share between pages and I have been messing around with App_Code classes which is great but I would also like to use code that affects drop down lists example:
Sub Set_FirmType(ByVal Sender As Object, ByVal E As EventArgs)
subcategories.Visible = "false"
supplycategories.Visible = "false"
[code]....
Is their a way to put this in my App_Code class?
View 1 Replies
Jun 12, 2009
We have 3 databases providers we use to connect to our databases: DB2, MS SQL, and Interbase. I would like to create a single generic database wrapper class that can be used to talk to all three just by passing in the correct connection string, username, password, and the provider desired.
I don't want to have to add references and import all three providers in the database class. Is this possible?I have done this before in Java using the Class.forName() function.
View 4 Replies
Aug 10, 2009
I happen to have these common procedures which I want to be used in my forms and usercontrols, with the form I can put those procedures in the base form which is being inherited but I happen to have a need to use those same procedures in my usercontrols, is there a way that I can have a common base class that I can use both for my form and usercontrol? I haven't used yet a base usercontrol since my usercontrols will not look the same so I have to put those procedures in each one of them and I find it rather cumbersome.
View 8 Replies
Dec 25, 2009
I do have a customized treeView which inherits from treeview and uses customized treenodes which inherit from treenode. It works, but each inherited method of the treeview using a treenode as a parameter forces me to do an explizit cast from treenode to my customized treenode to access the additional functionalitiy of my treenode class.
Is there a general way to avoid explizit casting all day long? E.g. telling my customized treeview that all it's properties, mehthods, etc. from now on are working with my customized treenodes instead the general treenode as default?
Turning off option strict is not an option because I want to keep this. Overriding each method, etc. is to cumbersome.
View 10 Replies
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
Nov 26, 2010
I have a vb .net application where the user can choose a directory into which an excel file is written. If the user selects a system directory (yes, my users do this, don't ask me why) then a System.Runtime.InteropServices.COMException is thrown at runtime. I am handling this exception telling the user to please select another directory.
View 1 Replies