Solved

inheritence quickie

Posted on 2006-07-24
4
235 Views
Last Modified: 2010-04-16
hi

i have an abstract base class "Base1.cs"

i have another concrete class "Organisation.cs" that inherits "Base1.cs"  Organisation : Base1

i have other classes that use Organisation.cs.

i want those classes that use Organisation.cs to be able to use "Base1.cs" methods but only via Organisation.cs.

What is the most appropriate scope i should give the methods on Base1.cs.

public ?  (this seems abit too general?)

thanks v much.

p.s - i know it cant be protected.


 
0
Comment
Question by:MrKevorkian
4 Comments
 

Expert Comment

by:muskok
ID: 17167753
You have to make the methods in Base1 protected and provide public methods in Organisation class. These public methods will call Base1's protected methods.
0
 
LVL 23

Expert Comment

by:apresto
ID: 17167767
Hi MrKevorkian,

You could created some Protected Properties in the Organisation class then anything that inherits Organsiation will be able to see those properties, which inturn look at inherited members from Base1

Apresto
0
 
LVL 13

Accepted Solution

by:
devsolns earned 400 total points
ID: 17168052
I would NOT recommend using protected scope.  In true OOP you should be able to do just fine without.  You state that you want derived classes to be able to use base1 methods but only by going through Organisation.  This is happening already because you made Base1 abstract.  No one will be able to instantiate that object and access its methods directly, only classes derived from that Base1 class can do so.  You'll also be missing out of many advantages of polymorphism and therefor questioning the use of inheritance here.

There are some good uses for protected accessibilty.  For example your event invoker methods.  You dont want to make them public but certainly want to provider accessibility for your derived classes to invoke directly so protected works.

Take care,
gp
0
 
LVL 1

Author Comment

by:MrKevorkian
ID: 17168117
i have decided to leave them public.  
i thought there might be another key word that was more suitable, but if there isnt thats fine.
i didnt really want to put extra properties on organisation.cs

thanks everyone.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question