Re: Is it possible to hide methods to certain classes?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




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.

From the context of regular life, a person is a passenger only some of
the time... only while they're on a plane. Therefore, making a
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.

.



Relevant Pages

  • did you hear this one
    ... A US passenger plane was flying in towards London Airport when the Co pilot ... that good old Limey beer, ...
    (soc.culture.irish)
  • Re: Legality of a flight
    ... A passenger wins a raffle prize or makes a donation to a charity, ... The airplane ride is flown by a private pilot, ... expense for the plane. ...
    (rec.aviation.piloting)
  • Kudos to ATC and Pilot
    ... FORT MYERS, Fla.-- A passenger landed a twin-engine plane at Southwest ... Florida International Airport after the pilot died in flight, ...
    (rec.aviation.ifr)
  • Re: Is it possible to hide methods to certain classes?
    ... Let's call them Plane, Pilot and Passenger. ... void EnterIn ...
    (microsoft.public.dotnet.languages.csharp)
  • OT Liberals raising pussies in America!
    ... Seniors Subdue Plane Passengers, ... Minneapolis-to-Boston flight Saturday night with erratic behavior. ... a former Boston police deputy superintendent and former Lawrence ... husband struggled with the agitated passenger, ...
    (alt.autos.toyota)