Solved

inheritence quickie

Posted on 2006-07-24
4
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

623 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