473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Hide method ( encapsulate)

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
}
}

Nov 17 '05 #1
2 1172
Matt <me*******@Hotmail.com> wrote:
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>

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
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
"Matt" wrote:
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
}
}

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ajai Kumar .R | last post by:
Hai all, I've two or more forms on my app. My requirement is, Have to show the first form asa the user press a button have to hide the first form and show the second form. If the user press the...
4
by: TMB333 | last post by:
I've researched as much as I can on the issue, but I've not found any clearly defined statement that acknowledges that the Hide method for a TabPage object just doesn't do what it's supposed to do....
9
by: Robb Gilmore | last post by:
Hello, This is probably an easy one, but I have not been able to figure it out so far. I have a tab control on a windows forms app. Depending on some business logic, I need to hide/show some...
0
by: Steve Blumenstein | last post by:
My application is MDI. After bringing up my main form (the parent), I then show a non-child form as a modal dialog box (FormBorderStyle=FixedDialog, displayed using the ShowDialog method from the...
8
by: Kejpa | last post by:
Hey there! I have a tabcontrol on one of my forms. Some of the tab should not be accessable (and thus invisible) until you give the correct password. But I can't hide the tab......
4
by: MLH | last post by:
I copied the code example below from A97 HELP. However, I get an error when I try to use something like frmMainMenu.Hide and am uncertain as to why. Ideas? The following example assumes two...
2
by: gene kelley | last post by:
I have a dialog form, frmDetails, that is opened from the main form: frmDetails.ShowDialog() The only way I have provided to close this dialog is via the "X" button. If frmDetails is just...
5
by: Amit | last post by:
Can anyone write the code to hide tabpage of tab control in windows form 2.0 Thanks, Amit
2
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, How can I query a Windows.Form control if it is hidden or not. I would like to toogle Hide/Show and not use a bool as control variable for this but simply query the form werther or not its...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.