473,835 Members | 2,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.WriteL ine("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 1190
Matt <me*******@Hotm ail.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 Substitutabilit y 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.co m>
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.WriteL ine("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
2511
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 escape key on second form, this should be hidded and should show the first form.... Can some one guide me how to achive this... (MUST USE SHOW & HIDE FORM PROPERTIES). I tried to achive this using the below code but when i check the Windows->Task...
4
13582
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. This appears to be a bug, or maybe I'm using it incorrectly? TabPage.Hide should hide the referenced TabPage object, should it not? Do I have to 'refresh' the Windows form somehow? The closest I've come to any means of hiding a TabPage from...
9
883
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 of the individual tabs. The tab page has no "visible" property. The tabpage class has a "hide" method, but this does not seem to make it disappear. I have been able to remove them via something like this:
0
983
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 main form). After the user enters the required data and clicks OK, this form does a Me.Hide to hide itself. As soon as the code hits the hide method, any app that was active on the desktop before starting my app (Excel, Word, etc. - it doesn't...
8
7537
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... tabSecrets1.Visible=false tabSecrets1.Hide will not work, the tab is visible :( Any help is appreciated Kejpa
4
1794
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 UserForms in a program. In UserForm1's Initialize event, UserForm2 is loaded and shown. When the user clicks UserForm2, it is hidden and UserForm1 appears. When UserForm1 is clicked, UserForm2 is shown again. ' This is the Initialize event...
2
2770
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 closed as normal, there is no visual problem (no repainting) with the main form. Now, I add this code to the the FormClosing event in the dialog, frmDetails:
5
13304
by: Amit | last post by:
Can anyone write the code to hide tabpage of tab control in windows form 2.0 Thanks, Amit
2
1783
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 hidden. regards than thanks Jesper.
0
9810
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10526
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10237
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6970
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5640
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5808
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4435
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.