How To Inherit A Abstract Class In Code Behind
Aug 25, 2009By Default code behind looks like --
Partial Public
Class InhAbs
[code].....
By Default code behind looks like --
Partial Public
Class InhAbs
[code].....
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 RepliesI created a vb.net dll which I am using in an unmanaged c++ project.When I try to create an object of the class, I am getting an error:cannot instantiate abstract class.Why would my class be abstract? How can I modify it so that it won't be abstract?
View 1 RepliesI can do this without problem.
Class A
End Class
Class B : Inherit A
End Class
Dim Obj1 As A = New B
class inherit from another class and implement an interface?
View 4 RepliesI have one interface that contains four functions. I have about 20 classes that implement this interface. Throughout each class, I see a lot of duplicate code, for example, there are constants declared at the beginning that are in every class. The method implementations (logic) of the interface are mostly the same.It contains duplicate structures. Is this a case where I can eliminate a lot of duplicate classes by implementing an abstract class instead of an interface. What I am striving for is too be able to put common methods from the abstract class as non-abstract methods and then methods that need their own implementation would be marked over-ridable. Can I put consts and structures in abstract classes? If so, that would eliminate a lot of duplicate code across the classes. Is there anything else I should look out for in the classes as a sign that I probably should be use an abstract class instead of an interface.
View 2 RepliesI'd like to make sure each of the subclasses has a certain nested class whose actual fields are up to the developer.
Nesting an abstract class inside the base abs. class doesn't seem to do the trick because during actual coding, both the nested abs. class and the nested class in the subclass both are available (show up in intellisense).
Having the base class implement an interface that includes a class doesn't work since interfaces only refer to methods that can be implemented, not classes (meaning implementing the interface requires implements methods, but says nothing about classes in the interface.
understanding difference between an interface and an abstract class which has no function with implementation?which is better abstract cls or interface in term of speed, features..?
View 11 RepliesI am developing a web app but is not satisfied with is architecture that I am following. The architecture is plain old conventional 3 tier architecture. What i want is follow some design pattern or architecture that will be help me in decoupling my code.I have idea about MVC and MVP architectures for Web App but i need different from that. I want to use OOPS concepts using abstract classes and interfaces, polymorphism etc in my app but not MVC and MVP. I dont know why?
View 2 Repliesexplain to me the differences between an abstract class and a class marked MustInherit?
Both can implement shared and instance constructors and logic. Both can/must be inherited.
So why use one over the other and what is the difference?
Edit: Sincerely apologize I have got my languages mixed up. Will mark correct answer as soon as I am allowed.
I've been playing around with implementing an abstract base class that using reflection accomplishes SQL to Object mapping.
I did some benchmarks and decided I wanted to implement a caching strategy for the property info of the objects (to prevent future lookups on them). My first instinct was to try and implement something like this.
Public MustInherit Class BaseModel
Implements IFillable
Private Shared PropertyCache As List(Of PropertyInfo)
[Code]....
I am trying to compile the following code and i am getting the error[code]...
View 2 RepliesBasically, I have a custom child form class which has events that will be passed to the parent. In the custom child form, I have a declaration of a "MustInherit" class that inherits the DevExpress User Control Class.
The reason for this, is I have many user controls that derive from this base class, and the child form can have an instance of any one of these controls, and doesnt care which. The only requirement is that the child form can handle the same events from each type of control the same way.
Some watered down code snippets(still pretty long unfortunately):
'''Inherited Class
Public Class ChildControlInheritedClass
[Code].....
If i have a class called A and a class called B, if B inherits A that means A is the super class and B is the subclass. I have been asked to describe why class A is not an abstract class but as i see it class A is an abstract class A, as it has been created for Class B to use in the future, is it something to do with Class B not being able to access the fields in Class A as although they are private by default?
[Code]...
I have an abstract class in vb.net with two subclasses. In the abstract class I have a constuctor that looks like this:[code]I would like to create a second constructor that doesn't take any arguments and just initializes the args to default values.[code]When I attempt to create a new subclass using the second constructor the compiler complains that I'm missing two args to the constructor.Is there a reason I can't overload the constructor in the abstract class?
View 2 RepliesWhat is the difference between a class with protected constructors and a class marked as MustInherit? (I'm programming in VB.Net but it probably equally applies to c#). The reason I ask is because I have an abstract class that I want to convert the constructors to shared/static methods. (To add some constraints). I can't do this because it's not possible to create an instance in the shared function.
[Code]...
I am creating an xlsx reader / writer for my application (based on OpenXML SDK 2.0). I want to read xlsx files and store the data contained in each row in a DTO/PONO. Further I want to read the xlsx file and then modify it and save it.Now my problem is not with the OpenXML SDK, I can do what I need to do.My problem is on how to structure my components. Specifically I have problems with the polymorphism at the lowest level of a Spreadsheet, the cell.A cell in Excel/OpenXML can have different types of data associated with it. Like a Time, Date, Number, Text or Formula. These different type need to be handled differently when read/written from/to a spreadsheet.I decided to have a common interface for all subtypes like TextCell, NumberCell, DateCell etc.Now when I read the cell from the spreadsheet the Method/Factory can decide which type of cell to create.
Now because the cell is an abstract from the real implementation it does not know / does not need to know of what type it is. For writing / modifying the cell I solve this problem by calling .write(ICellWriter) on the cell I want to persist. As the cell itself knows what type of data it contains, it knows which method of ICellWriter it needs to call (static polymorpism).Writing to the xlsx file is no problem. My problem is, how do I get the data out of my cell into my DTO/PONO without resorting to type checking -> If TypeOf variable is ClassX then doesomething End If. As Methods / Properties have to have different Signatures and differentiating by only using a different return type is not allowed.The holder (collection, in this case a row of a table/spreadsheet) of the objects (refering to the cells) does not know the concrete implementations. So for writing a cell I pass it a Cellwriter. This Cellwriter has overloaded methods like Write(num as Integer), Write(text as String), Write(datum as Date). The cell object that gets this passed to it then calls the Write() method with the data type it holds. This works, as no return value is passed back.After some thinking about the problem I came to realize that it's not possible without reflection or knowledge of what type of cell I am expecting. Basically I was trying to recreate a spreadsheet or something with similar functionality and way too abstract/configurable for my needs.
I have recently come across some code that has the following. First there is a Interface with the following function Function Validate() As Boolean. That interface is then implemented in the an 'ABSTRACT' class like this.
Public MustOverride Overloads Function Validate() As Boolean Implements IBusinessEntity.Validate
Question 1: Why use Overloads in the Abstract class implementation.
Question 2: The Abstract class is then inherited into a class (TestClass). In TestClass the Validate function is implemented as follows Public Overloads Overrides Function Validate() As Boolean. I understand the Overrides keyword is to insure that this is the version of the Validate that you want called and not the Abstract class version but why again use the keyword Overloads?
From what I understand you can overload a constructor of a class by simply changing the constructor signature. Also, you overload Methods and Properties of a class by using the Keyword Overloads. But why do it when your implementing an Interface method, or an Abstract Class method that's inherited.
How to simplify this, 2 method in class are identical.First class.
Public Class Gui
Inherits System.Web.UI.Page
Public Sub CreateStyleLink(ByVal StyleArray() As String)
[code].....
How to simplify this, 2 method in class are identical.[code]
View 3 RepliesI have the following sample code in a VB.NET console application. It compiles and works, but feels like a hack. Is there a way to define EmptyChild so that it inherits from Intermediate(Of T As Class) without using the dummy EmptyClass?
Module Module1
Sub Main()
Dim Child1 = New RealChild()[code].....
The other way to do this would be to move the generic code out of the Base class and then create 2 Intermediate classes like this [code]...
Then RealChild would inherit from the generic Intermediate and EmptyChild would inherit from the non-generic Intermediate. My problem with that solution is that the Base class is in a separate assembly and I need to keep the code that handles the generic type in that assembly. And there is functionality in the Intermediate class that does not belong in the assembly with the Base class.
i'm working with different classes and different constructors. It's working fine until i try to inherit a class that also has a constructor. vb asks for mybase.new but when i add that vb says that a constructor cannot call itself, when i try it in a different way vb asks the parameters of the constructor of the class that i want to inherit.
View 11 Replieswhy is it that Strings are declared notinheritable? plus is there a base class of Integer for us to inherit from?
View 7 Replies<edit on 7th July, 2010. Please see my 4th post in this threadfor the reason I have marked the post by bpellAS ANSWER </edit>
View 1 RepliesHow to create a class which inherits from a data type, specifically from Char data type? I just want to add one property to it. If it's not possible, are there any other ways to accomplish this?
View 2 RepliesI have problem in Form controls. I inherit label control in a class Mylabel i use this label on my form not standard label control. now i want change the Font all Mylabel in my form then it not change Font when i use standard label control it's work.
I use this code
For Each Ctrl as Control In Me.Controls
Ctrl.font= new Font("Arial",10)
next
I am writing a game editor, and have a lot of different "tool" objects. They all inherit from BTool and have the same constructor. I would like to dynamically populate a toolbox at runtime with buttons that correspond to these tools, and when clicked have them create an instance of that tool and set it as the current tool. Is this possible, and if so will it be better/easier than creating those buttons by hand?
View 3 Repliesmy form displays locations and owners for a same product, the forms have a data grid view that actually takes in the details of the location and owner of that particular product. a product can have multiple owners and locations once its manufactured over time, the forms actually display this all i need is some kind of business logic that can actually manage the historical events of the location and the owner that when a user actually goes in and adds a new entry, the end date of the previous owner gets reduced to one less than the start date of the new owner. this in formation is stored in business layers called the owner collection and the location collection, i am not able to actually inherit or call the location or the owner collection class in the classes.
View 1 RepliesI 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]...
I have an abstract class which requires a delegate to function. I pass the delegate into the constructor. Now that I have a non default constructor I need to call the abstract class's constructors from the concrete class which means that I need to use MyBase.New(...). I have included a quick example below.
Public MustInherit Class BaseClass
Public Delegate Sub WorkMethod()
Private _Work As WorkMethod
[code]....
I have tried to do this but I keep getting the following error: "Implicit reference to object under construction is not valid when calling another constructor".Can I not do what I am trying to do above? I initially had the delegate setup in its own setter method. But then I am creating a deceptive API because it does require a point to a method to work properly.