473,322 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Abstract Class

Hi,
My customer has an abstract class with some interface A . he wants me to
Inherit his Class and implement the intrface with some functionality in a new
class B.

I need to know how he would access my implementation without a Reference .

Can a base class generates his derived classes ? Like when i will use some
method it will be happen in others derived classes ?

Br
Ornez
Nov 21 '05 #1
7 1494
I don't know if I understand, but, If your customer has an Abstract class
and wants you to implement an interface then all of the functionality will
come from the interface implementation plus any additional functionality you
design; an abstract class cannot be instantiated directly (MustInherit).
Consider the System.IO.Stream object. You can declare an object as a stream
but a derived class must be assigned to it.

'Cannot do
Dim Stream as NEW System.IO.Stream

'Can do
Dim Stream as System.IO.Stream
Stream = New System.IO.Memory

So, your customer can access your implementation by instantiating his
abstract class with a value of your derived class.

I could be way off here, someone will correct me shortly if that is the
case.

Hope this helps,
Jared

"Ornez" <Or***@discussions.microsoft.com> wrote in message
news:2B**********************************@microsof t.com...
Hi,
My customer has an abstract class with some interface A . he wants me to
Inherit his Class and implement the intrface with some functionality in a
new
class B.

I need to know how he would access my implementation without a Reference .

Can a base class generates his derived classes ? Like when i will use some
method it will be happen in others derived classes ?

Br
Ornez

Nov 21 '05 #2
It was supposed to read
Stream = New System.IO.MemoryStream, I think my spell checker got a hold of
it.
Stream = New System.IO.Memory


Nov 21 '05 #3
Hi Jared,

First,thank you for your quick respond.

Let say that Class A has MustOverride Sub OnMessage(ByVal message As string)
and i need to implement in derived class, to popup a message box when the
sub is called . you wrote "So, your customer can access your implementation
by instantiating his abstract class with a value of your derived class. "
..What value of my derived Class ?

Thanks
Ornez

"Jared" wrote:
It was supposed to read
Stream = New System.IO.MemoryStream, I think my spell checker got a hold of
it.
Stream = New System.IO.Memory


Nov 21 '05 #4
* "=?Utf-8?B?T3JuZXo=?=" <Or***@discussions.microsoft.com> scripsit:
Let say that Class A has MustOverride Sub OnMessage(ByVal message As string)
and i need to implement in derived class, to popup a message box when the
sub is called . you wrote "So, your customer can access your implementation
by instantiating his abstract class with a value of your derived class. "
.What value of my derived Class ?


An instance of the derived class can be seen as an instance of its base
class too. You can instantiate the base class by deriving a class from
it and instantiating the derived class.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5
Ornez,
Consider the following example: In block one, we have a declaration for
an object of type "AbstractClass", notice how you have to declare it without
the new keyword; we have initialized it with the value of a different class,
one of type "DerivedClass"
AbstractClass doesn't do anything except define the base functionality
(those elements that every derived class will have in common). The rest of
the functions and properties are DEFINED in the Interface. All of the actual
work is performed in the DerivedClass.

To see how this works do the following:
Create a new form, switch to code view, paste all the code in block two at
the very end of the file. Now, switch back to design view, add a button, in
the click event paste the contents of block one. Set a breakpoint on block
one and step through the code to see what happens. Herfried is my Newsgroup
Idol, but, he is way above most of us and it's hard to understand his points
at times. This small example should give you an idea of Inheritenance.
Microsoft has several good webcasts and videos; I recommend watching the
webcasts on Inheritance and Interfaces
http://msdn.microsoft.com/vbasic/atthemovies/
http://msdn.microsoft.com/vbtv/
http://msdn.microsoft.com/showsandwebcasts/default.aspx

Jared

'<Block One>
Dim Abstract As AbstractClass = New DerivedClass
With Abstract
.DoSomething("DoingSomething")
.MyProperty = "Setting the Property of myvalue"
.OnMessage()
End With
'</Block One>

<Block Two>
Public MustInherit Class AbstractClass
Implements MyInterface

MustOverride Function DoSomething(ByVal Something As String) As String
Implements MyInterface.DoSomething
MustOverride Property MyProperty() As String Implements
MyInterface.MyProperty
MustOverride Sub OnMessage() Implements MyInterface.OnMessage

End Class

Public Interface MyInterface

Sub OnMessage()
Function DoSomething(ByVal Something As String) As String
Property MyProperty() As String

End Interface

Public Class DerivedClass
Inherits AbstractClass

Private _mMyproperty As String
Public Overrides Function DoSomething(ByVal Something As String) As
String
MessageBox.Show("Something with a value of: " & Something & "
happened")
End Function
Public Overrides Property MyProperty() As String
Get
Return Me._mMyproperty
End Get
Set(ByVal Value As String)
Me._mMyproperty = Value
End Set
End Property
Public Overrides Sub OnMessage()
MessageBox.Show("OnMessage Handled")
End Sub

End Class
</Block Two>

"Ornez" <Or***@discussions.microsoft.com> wrote in message
news:C8**********************************@microsof t.com...
Hi Jared,

First,thank you for your quick respond.

Let say that Class A has MustOverride Sub OnMessage(ByVal message As
string)
and i need to implement in derived class, to popup a message box when the
sub is called . you wrote "So, your customer can access your
implementation
by instantiating his abstract class with a value of your derived class. "
.What value of my derived Class ?

Thanks
Ornez

"Jared" wrote:
It was supposed to read
Stream = New System.IO.MemoryStream, I think my spell checker got a hold
of
it.
> Stream = New System.IO.Memory


Nov 21 '05 #6
On 2004-09-11, Ornez <Or***@discussions.microsoft.com> wrote:
Hi,
My customer has an abstract class with some interface A . he wants me to
Inherit his Class and implement the intrface with some functionality in a new
class B.

I need to know how he would access my implementation without a Reference .

Can a base class generates his derived classes ? Like when i will use some
method it will be happen in others derived classes ?


I'm guessing here a bit, but mostly likely your customer wants you to
implement MustOverride functions which will then be called automatically
from the base class when your derived class is instantiated. The base
class doesn't need to generate the derived class in this case, or know
very much about the derived class other than the fact that it implements
the MustOverride functions.

Public MustOverride Class AbstractBaseClass

Protected MustOverride Foo(ByVal sb as StringBuilder)

Public Sub Bar()
Dim sb as New StringBuilder
Foo(sb)
Console.WriteLine(sb.ToString())
End Sub

End Class

Public Class DerivedClass
Inherits AbstractBaseClass

Protected Overrides Sub Foo(ByVal sb As System.Text.StringBuilder)
sb.Append("Hello World")
End Sub
End Class
Dim d as New DerivedClass
d.Bar()

The Bar function will call the derived class's Foo method, even though
the base class doesn't even know the name of the derived class, what
assembly it exists it, and quite possible doesn't even have a reference
to the appropriate assembly.

It's all in the nature of virtual functions and how they work.

Nov 21 '05 #7
I must have a few things since I've been posting, in the past Herfried used
to "tear through" almost every post I made, now he is supporting my
response. ;-)

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2q************@uni-berlin.de...
* "=?Utf-8?B?T3JuZXo=?=" <Or***@discussions.microsoft.com> scripsit:
Let say that Class A has MustOverride Sub OnMessage(ByVal message As
string)
and i need to implement in derived class, to popup a message box when the
sub is called . you wrote "So, your customer can access your
implementation
by instantiating his abstract class with a value of your derived class. "
.What value of my derived Class ?


An instance of the derived class can be seen as an instance of its base
class too. You can instantiate the base class by deriving a class from
it and instantiating the derived class.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8

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

Similar topics

4
by: Tony Johansson | last post by:
Hello! Assume you have an abstract class called Body and a derived class called cylinder. When you have an abstract class you can't instansiate an object. As you can see in the abstract class...
12
by: Daedalus.OS | last post by:
Ok first I'm pretty new to OOP, so my question may sound stupid to some of you. If the only answer you can provide is "get a book about OOP" then don't loose your time and mine cause it's already...
2
by: Dave Veeneman | last post by:
Is is legal to declare abstract members in non-abstract classes? How about non-abstract members in abstract classes? I am writing a base class with three derived classes. The base class will...
6
by: Dan Sikorsky | last post by:
If we were to define all abstract methods in an abstract class, thereby making that class non-abstract, and then override the heretofore 'abstract' methods in a derived class, wouldn't that remove...
7
by: jason | last post by:
In the microsoft starter kit Time Tracker application, the data access layer code consist of three cs files. DataAccessHelper.cs DataAcess.cs SQLDataAccessLayer.cs DataAcccessHelper appears...
0
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never...
4
by: N.RATNAKAR | last post by:
hai, what is abstract class and abstract method
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
4
by: David Zha0 | last post by:
Hi, "when we call a virtual method, the runtime will check the instance who called the method and then choose the suitable override method, this may causes the performance drop down", is this...
6
by: Miguel Guedes | last post by:
Hello, I recently read an interview with Bjarne Stroustrup in which he says that pure abstract classes should *not* contain any data. However, I have found that at times situations are when it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.