Re: Is it possible to hide methods to certain classes?
- From: "Bruce Wood" <brucewood@xxxxxxxxxx>
- Date: 13 Jan 2007 18:14:42 -0800
Fabio wrote:
"GroZZleR" <grozzler@xxxxxxxxx> ha scritto nel messaggio
news:1168681499.456708.162430@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hey all,
I have 3 classes. Let's call them Plane, Pilot and Passenger.
I'm trying to restrict Passenger's access to Plane's more intimate
methods, but allow Pilot to use 'em.
Right now I have this "useless" interface that creates basic methods,
then Plane implements that interface to add more.
For example:
PlaneInterface
- Enter()
- Exit()
Plane : PlaneInterface
- TakeOff()
- Land()
When the passenger needs to use the Plane, I downcast the object to a
PlaneInterface so that Passenger only sees the Enter and Exit methods.
Is there a better method to restricting access of certain methods to
certain classes?
If you cannot join the puzzle pieces means that... they don't have joinable
shapes.
Is the subject that do actions, not the object:
class FlyingPerson
void EnterIn(Plane)
void Exit()
class Passenger : FlayingPerson
void LockTheBelt()
class Pilot
void BeginPilot()
void EndPilot()
class Plane
List<Passenger> Passengers
List<Pilot> Pilots
void TakeOff()
void Land()
In this way your pieces can interact with each others without strange
workarounds.
I can see this design getting into a lot of trouble later on.
the time... only while they're on a plane. Therefore, making aFrom the context of regular life, a person is a passenger only some of
passenger a whole separate class doesn't make much sense. Besides, what
do you do when a pilot flies as a passenger? Do you record them as two
separate entities: person-as-pilot being different from
person-as-passenger? You might, or you might not.
If, however, your system only ever sees passengers and doesn't see them
in any other context, then this sort of design will work.
I prefer the original design: just use interfaces to implement the
various capabilities of Person, and then you can write code that deals
with people in their different aspects and roles, while having only one
object representing one person.
.
- Follow-Ups:
- References:
- Is it possible to hide methods to certain classes?
- From: GroZZleR
- Re: Is it possible to hide methods to certain classes?
- From: Fabio
- Is it possible to hide methods to certain classes?
- Prev by Date: Re: Boxing and Unboxing ??
- Next by Date: Re: Boxing and Unboxing ??
- Previous by thread: Re: Is it possible to hide methods to certain classes?
- Next by thread: Re: Is it possible to hide methods to certain classes?
- Index(es):
Relevant Pages
|