Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / June 2006

Tip: Looking for answers? Try searching our database.

Inheriting and Extending internal class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul Say - 01 Jun 2006 00:57 GMT
This is the situation I have a base class _Job that has an internal class PropertyNames (see code )

public abstract class _JobBase
{
   private int _JobId;
   private int _JobName;

   public virtual int JobId
   {
       get{return this._JobId;}
       set{this._JobId = value;}
   }

   public virtual string JobName
   {
       get{return this._JobName;}
       set{this._JobName = value;}
   }

   public class PropertyNames{
       public const string JobId = "JobId";
       public const string JobName= "JobName";
   }

}

When inheriting from _Job if I want to extend the PropertyNames inner class I am doing the following

public class Job:_JobBase
{
   public string JobNameExtended
   {
       get{return this.JobId.ToString() & " - " & this.JobName;}
   }

   public new class PropertyNames:_JobBase.PropertyNames
   {
       public const string JobNameExtended = "JobNameExtended";
   }
}

What I want to know is if this is the correct way of extending an inner class as this works, or if there is a better way.

Paul
Carl Daniel [VC++ MVP] - 01 Jun 2006 01:59 GMT
That works just fine.  

Using a class as a container for a static list of names seems a bit dodgy - with all members static (const is static), there's no point in ever creating an instance of this class, in which case there's also no point in deriving from the class.  Of course, if there's more to the PropertyNames class than you're showing then the use of inheritance (or even of a class) might be justified.

-cd
 This is the situation I have a base class _Job that has an internal class PropertyNames (see code )

 public abstract class _JobBase
 {
     private int _JobId;
     private int _JobName;

     public virtual int JobId
     {
         get{return this._JobId;}
         set{this._JobId = value;}
     }

     public virtual string JobName
     {
         get{return this._JobName;}
         set{this._JobName = value;}
     }

     public class PropertyNames{
         public const string JobId = "JobId";
         public const string JobName= "JobName";
     }

 }

 When inheriting from _Job if I want to extend the PropertyNames inner class I am doing the following

 public class Job:_JobBase
 {
     public string JobNameExtended
     {
         get{return this.JobId.ToString() & " - " & this.JobName;}
     }

     public new class PropertyNames:_JobBase.PropertyNames
     {
         public const string JobNameExtended = "JobNameExtended";
     }
 }

 What I want to know is if this is the correct way of extending an inner class as this works, or if there is a better way.

 Paul

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.