473,729 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inheritance question

I have three classes:

Core Assembly
Application - creates instances of User using Activator.Creat eInstance
Item - marked MustInherit; has an Init method

UserPlugin Assembly
User - Inherits Item, has an Init method

I would like to be able to call the Init method from the Application where
the Item.Init would fire before the User.Init method. Moreover, I don't
want the Init method on either class to be visible outside of the Core
assembly.

I don't want to use the New sub, as i don't always want the logic in the
Init to be run when an instance is created. I would like to hide the New
method from public use, but the CreateInstance method seems to require one.

I would appreciate some advice on this. Thanks.

Craig Buchanan
Apr 28 '06 #1
2 1103
See if this sample does what you want:

Namespace MyCompany.Core

Public MustInherit Class Item
Protected mblnWasInited As Boolean

Protected Sub New()

Dim CallID As Integer = MyCompany.Commo n.AppHelper.Get NextMethodCall

Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format("-----{0}:Begin MyCompany.Core. Item:{1}", CallID, "New()"))
mblnWasInited = False
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format("-----{0}:End MyCompany.Core. Item:{1}", CallID, "New()"))

End Sub

Protected Friend Overridable Sub Init()

Dim CallID As Integer = MyCompany.Commo n.AppHelper.Get NextMethodCall

Trace.Indent()
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin MyCompany.Core. Item:{1}", CallID, "Init()"))
Init(False)
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End MyCompany.Core. Item:{1}", CallID, "Init()"))
Trace.Unindent( )

End Sub

Protected Friend Overridable Sub Init(ByVal SetFlag As Boolean)

Dim CallID As Integer = MyCompany.Commo n.AppHelper.Get NextMethodCall

Trace.Indent()
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin MyCompany.Core. Item:{1}", CallID, "Init(bool) "))
If SetFlag Then mblnWasInited = SetFlag
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End MyCompany.Core. Item:{1}", CallID, "Init(bool) "))
Trace.Unindent( )

End Sub

End Class

End Namespace

Namespace MyCompany.Plugi ns
Public Class User
Inherits MyCompany.Core. Item

Public Sub New()
MyBase.new() 'Mybase.new has to be called before any other line of
code in the constructor

Dim CallID As Integer = MyCompany.Commo n.AppHelper.Get NextMethodCall

Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin MyCompany.Plugi ns.User:{1}", CallID, "New()"))
'
'
'
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End MyCompany.Plugi ns.User:{1}", CallID, "New()"))
End Sub

Friend Shadows Sub Init()

Dim CallID As Integer = MyCompany.Commo n.AppHelper.Get NextMethodCall

Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin MyCompany.Plugi ns.User:{1}", CallID, "Init()"))
Trace.Indent()
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin mybase:{1}", CallID, "Init()"))
MyBase.Init()
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End mybase:{1}", CallID, "Init()"))
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin local init logic", CallID))
'
' Custom implementation
'
'
Trace.Indent()
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin setting init flag", CallID))
mblnWasInited = True
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End setting init flag", CallID))
Trace.Unindent( )
'
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End local init logic", CallID))
Trace.Unindent( )
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End MyCompany.Plugi ns.User:{1}", CallID, "Init()"))
End Sub

End Class
End Namespace

Namespace MyCompany.Commo n
Friend Class AppHelper
Private Shared mTracingOn As Boolean
Private Shared mCallID As Integer

Shared Sub New()
mTracingOn = True
mCallID = Integer.MinValu e
End Sub

Public Shared ReadOnly Property TracingOn() As Boolean
Get
Return mTracingOn
End Get
End Property

Public Shared Function GetNextMethodCa ll() As Integer
mCallID += 1
Return mCallID
End Function

End Class
End Namespace

"Craig Buchanan" <na**@company.c om> wrote in message
news:Ox******** *****@TK2MSFTNG P02.phx.gbl...
I have three classes:

Core Assembly
Application - creates instances of User using Activator.Creat eInstance
Item - marked MustInherit; has an Init method

UserPlugin Assembly
User - Inherits Item, has an Init method

I would like to be able to call the Init method from the Application where
the Item.Init would fire before the User.Init method. Moreover, I don't
want the Init method on either class to be visible outside of the Core
assembly.

I don't want to use the New sub, as i don't always want the logic in the
Init to be run when an instance is created. I would like to hide the New
method from public use, but the CreateInstance method seems to require
one.

I would appreciate some advice on this. Thanks.

Craig Buchanan

Apr 28 '06 #2
thanks, i'll take a look and let you know.

"AMDRIT" <am****@hotmail .com> wrote in message
news:eC******** ******@TK2MSFTN GP03.phx.gbl...
See if this sample does what you want:

Namespace MyCompany.Core

Public MustInherit Class Item
Protected mblnWasInited As Boolean

Protected Sub New()

Dim CallID As Integer = MyCompany.Commo n.AppHelper.Get NextMethodCall

Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format("-----{0}:Begin MyCompany.Core. Item:{1}", CallID, "New()"))
mblnWasInited = False
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format("-----{0}:End MyCompany.Core. Item:{1}", CallID, "New()"))

End Sub

Protected Friend Overridable Sub Init()

Dim CallID As Integer = MyCompany.Commo n.AppHelper.Get NextMethodCall

Trace.Indent()
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin MyCompany.Core. Item:{1}", CallID, "Init()"))
Init(False)
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End MyCompany.Core. Item:{1}", CallID, "Init()"))
Trace.Unindent( )

End Sub

Protected Friend Overridable Sub Init(ByVal SetFlag As Boolean)

Dim CallID As Integer = MyCompany.Commo n.AppHelper.Get NextMethodCall

Trace.Indent()
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin MyCompany.Core. Item:{1}", CallID, "Init(bool) "))
If SetFlag Then mblnWasInited = SetFlag
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End MyCompany.Core. Item:{1}", CallID, "Init(bool) "))
Trace.Unindent( )

End Sub

End Class

End Namespace

Namespace MyCompany.Plugi ns
Public Class User
Inherits MyCompany.Core. Item

Public Sub New()
MyBase.new() 'Mybase.new has to be called before any other line of
code in the constructor

Dim CallID As Integer = MyCompany.Commo n.AppHelper.Get NextMethodCall

Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin MyCompany.Plugi ns.User:{1}", CallID, "New()"))
'
'
'
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End MyCompany.Plugi ns.User:{1}", CallID, "New()"))
End Sub

Friend Shadows Sub Init()

Dim CallID As Integer = MyCompany.Commo n.AppHelper.Get NextMethodCall

Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin MyCompany.Plugi ns.User:{1}", CallID, "Init()"))
Trace.Indent()
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin mybase:{1}", CallID, "Init()"))
MyBase.Init()
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End mybase:{1}", CallID, "Init()"))
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin local init logic", CallID))
'
' Custom implementation
'
'
Trace.Indent()
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin setting init flag", CallID))
mblnWasInited = True
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End setting init flag", CallID))
Trace.Unindent( )
'
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End local init logic", CallID))
Trace.Unindent( )
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End MyCompany.Plugi ns.User:{1}", CallID, "Init()"))
End Sub

End Class
End Namespace

Namespace MyCompany.Commo n
Friend Class AppHelper
Private Shared mTracingOn As Boolean
Private Shared mCallID As Integer

Shared Sub New()
mTracingOn = True
mCallID = Integer.MinValu e
End Sub

Public Shared ReadOnly Property TracingOn() As Boolean
Get
Return mTracingOn
End Get
End Property

Public Shared Function GetNextMethodCa ll() As Integer
mCallID += 1
Return mCallID
End Function

End Class
End Namespace

"Craig Buchanan" <na**@company.c om> wrote in message
news:Ox******** *****@TK2MSFTNG P02.phx.gbl...
I have three classes:

Core Assembly
Application - creates instances of User using Activator.Creat eInstance
Item - marked MustInherit; has an Init method

UserPlugin Assembly
User - Inherits Item, has an Init method

I would like to be able to call the Init method from the Application
where the Item.Init would fire before the User.Init method. Moreover, I
don't want the Init method on either class to be visible outside of the
Core assembly.

I don't want to use the New sub, as i don't always want the logic in the
Init to be run when an instance is created. I would like to hide the New
method from public use, but the CreateInstance method seems to require
one.

I would appreciate some advice on this. Thanks.

Craig Buchanan


May 1 '06 #3

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

Similar topics

1
3748
by: KK | last post by:
Windows Forms Inheritance, Incomplete? I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the application contains couople of forms which have a consistant look and also shares SOME similar functionality between the forms.
2
2200
by: KK | last post by:
** Posting it here cause after couple of days no body responded.** I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the application contains couople of forms which have a consistant look and also shares SOME similar functionality between the forms.
4
12820
by: Dave Theese | last post by:
Hello all, The example below demonstrates proper conformance to the C++ standard. However, I'm having a hard time getting my brain around which language rules make this proper... The error below *should* happen, but my question to the community is *why* does it happen? Any answer will be appreciated, but a section and paragraph number from the C++ Standard would be especially appreciated.
8
7830
by: __PPS__ | last post by:
Hello everybody, today I had another quiz question "if class X is privately derived from base class Y what is the scope of the public, protected, private members of Y will be in class X" By scope they meant public/protected/private access modifiers :) Obviously all members of the base privately inherited class will be private, and that was my answer. However, the teacher checked my answers when I handed in, and the problem was that I had...
22
23379
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete examples?
45
6351
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using parameters, I get CS1501 (no method with X arguments). Here's a simplified example which mimics the circumstances: namespace InheritError { // Random base class. public class A { protected int i;
6
2099
by: VR | last post by:
Hi, I read about Master Pages in ASP.Net 2.0 and after implementing some WinForms Visual Inheritance I tryed it with WebForms (let's say .aspx pages, my MasterPage does not have a form tag itself so, cannot be called a WebForm itself, the child pages will implement forms). I created a Master.aspx page and removed all HTML from it, added some code to the .aspx.vb file to add controls to my page. Then I created a Child.aspx and changed the...
5
2472
by: Noah Roberts | last post by:
Is there anything that says that if you virtually inherit from one class you have to virtually inherit from anything you inherit from?
3
1840
by: RSH | last post by:
I have a simple question regarding inheritance in a web form. I have a DropDownList in an aspx form. It is called DropDownList1 I have a class that will be overriding the render event so I have a snippet of this class: Public Class CustomDDL Inherits DropDownList
8
328
by: RSH | last post by:
Hi, I am working on some general OOP constructs and I was wondering if I could get some guidance. I have an instance where I have a Base Abstract Class, and 4 Derived classes. I now need to make a list class that will store the objects. My question is how do I go about creating the list class...I am assuming it should be a standalone class that uses an arraylist to store the objects. If I go that route how do I instantiate the...
0
8921
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9284
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9202
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9148
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8151
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4528
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2165
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.