Hide method ( encapsulate)

  • Thread starter Thread starter Matt
  • Start date Start date
M

Matt

Hiding Method. How to Hide tx.carry()
I want tx.carry not to be reached on test();
any ideas?
public abstract class Car
{
public abstract void run();
public abstract void carry();
}
public class Taxi : Car
{
public override void run()
{Console.WriteLine("Taxi");}
}
public class test
{
public static void main(string[] args)
{
Taxi tx = new Taxi();
tx.run();
tx.carry();// i dont want this to be here
}
}
 
Matt said:
Hiding Method. How to Hide tx.carry()
I want tx.carry not to be reached on test();
any ideas?

You can't. Liskov's Substitutability Principle says that you must be
able to treat a Taxi as a Car - therefore you have to be able to call
Carry.

<snip>
 
Hi Matt,
why not just make carry() a protected method, so that classes that inherit
from Car can see this method internally, but still do not expose this on the
public interface of the object.

Mark R Dawson
http://www.markdawson.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top