Function only visible to a specific class

Hi All
I am implementing a tree hierachy with a classes call 'Tree" and "Node". Inside the Node class, I have a function call "setName" for setting the name of the node. This function will only ever be used by Tree for setting the name of the nodes inside the tree. Is there anyway I can make the restriction so that this function will only ever be visible to the class "Tree" only?

It also depends the way you want to model your Tree/Node concepts.
In particular you will often hear something along the lines of: "if the setName function is only Tree's business, then it should be a method of Tree itself".
You could object that even if this method is implemented in Tree, you need a way to associate the name to the corresponding object held in the tree.
But stuffing the name in the Node itself is maybe not the right way: if the name property does not belong to the entity held in the node (if the name concept is only relevant to the Tree), then it could be stored in another attribute of the Tree class (such as a Map of names keyed by the path).
Now if you want other classes to read that name (but not set it), you have several options:
1) If your Node class only represent the building block of a tree structure (with the wiring, management of children, etc...),
then other classes maybe don't need to see it : if they want to know the data at a certain node in the tree, they can ask the tree, something along Tree.getDataAtpath(...)..
Even if these other class need other things like getNumberOfChildren, and especially getNameAtPath(...), you can write your Tree class to provide these services.
Note that I assummed above that you have a path notion, independant of the name data, to identify nodes in the tree structure, otherwise you wouldn't need to read the name from the Tree. In case your client classes can get a Node reference without knowing about the Tree or the path in the Tree, you probably fall in case 2.
2) Now if your Node class represents the building block of a tree structure PLUS the data it contains:
First note that this model is not very flexible because it mixes the wiring of a tree structure with the business logic of the entity contained in the tree structure.
But one way you can model it is to separate the concerns in two interfaces (say, GenericNode and MyNodeData), implemented by the same NodeImpl class, and expose only MyNodeData to the outside. If your setName method belongs to the GenericNode, tree can invoke it but client classes will not even know it exists.
Note that this doesn't protect against malicious calls (client code could simply cast the reference to GenericNode or NodeImpl). It just protects from accidental usage. It reminds the convention that "only Tree should set the name", but does not enforce it.
What do you think of a pedantic generalization such as:
The Java replacement to C++'s [i]friend concept is to spread functionalities among interfaces.?

Similar Messages

  • To more specific class: Cant find strict numeric, only numeric

    Im trying to read a control property by reference from some controls that are in a cluster.
    I want to cast the property's reference to a more specific class: strict numeric, but I can only find 'Numeric' which leaves me with variant data.
    Any help?
    Solved!
    Go to Solution.

    Hello,
    I think you can't (not fully sure though). What you can do is get the "Representation" property, that tells you if it's I32 or DBL or else (as an enum) and with this information you can get the value from the variant.
    See :
    Hope this helps
    EDIT :
    Oh... I see now that there IS a way, thanks for that pincpanther :-o
    When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"

  • I am having difficulties loading pages. For example: I am on the powerschool web site looking at my child's grades. I want to get into a specific class and the page either takes many minutes to load or I get the error message that the page can't load. He

    Can't get into specific class grades. It's not just here though; many pages load and load and load taking an extremely long time only to get an error message.
    == URL of affected sites ==
    http://ps.hibbing.k12.mn.us/public/home.html

    Hello, could this be it?
    Java for OS X 2012-006: How to re-enable the Apple-provided Java SE 6 applet plug-in and Web Start functionality
    http://support.apple.com/kb/HT5559

  • How to restrict the accessibility of a class to specific class(es)

    How can I restrict accessibility of a class (instantiating or using) to a specific class or a set of classes. For example, I have a class 'CreditCard'. I want to limit its accessibility to a specific class 'CreditCardManager'. i.e., anyone could only create or use objects of 'CreditCard' class from 'CreditCardManager' class only.
    This may look like 'friend' functionality in c++. But it is not. The private members should not be accessed from the manager class.

    Define a CreditCard interface:
    public interface CreditCard {
    }Put the implementation inside CreditCardManager:
    public class CreditCardManager {
        private /* static (?) */ class CreditCardImpl implements CreditCard {
        public CreditCard newCreditCard(...) {
            CreditCard  cc = new CreditCardImpl();
            return cc;
    }Since you are going on about it, I assume CreditCard is a key concept in your app, so there are probably other reasons to make it an interface too. For example, so that youi can mock it in unit tests.

  • How to modify a specific class in jar file ?

    I've downloaded a jar file for applet, the jar file works fine... but when I extract a specific class file from the jar file and just recompie it from my IDE (Eclipse) without even making any change and then compress again jar class files including the new modified class file instead of the old one (without any modifications to other classes)... then I get
    (NoSuchMethodError ) exception whenever methods of other classes are invoked from within the modified class !!
    ...The manifist file of the jar file reads the following line
    Created-By: 1.4.0_01 (Sun Microsystems Inc.)
    I thought it means that jar class files were built using JDK 1.4.0_01 ...I used JDK 1.5.0_01 in my IDE...
    I thought JRE incompatiblity was the reason of the problem so I downloaded JRE 1.4.0_01 and used it to build this class file... but i got the same exception..
    so what is the main reason of the problem ? ...should I make changes to IDX files accompanying applet jar files ??
    If no, then how can I overcome this problem and be able to change and rebuild a specific class from this jar file ?
    (I cannot rebuild all classes in jar because there are errors I cannot resolve !!)

    Could you please clarify: do you want to run your project or a project from an independent jar?
    In the first case just select Run Project from the project context menu or select a class with main method and click Run File in the class context menu.
    Regarding the second case:
    - I don't think there is such a feature in the IDE (running third party jars is not an IDE function). Could you explain why you need this?

  • SUBMENU ONLY VISIBLE ON CLICK

    I used the spry vertical menu bar. It is possible to make the submenu only visible if you click one of the items?

    Thank you for your reply and advice!
    Another option, is make the submenu permanently visible when I select one of the items. It is important to signalize the content that is being displayed on the page.
    I need to change de Java scrip but i have explore the code and I don't know how. It is complex change this function in java script? Can you help me about this??
    Thank you.

  • Averaging only visible numbers in a column

    I am trying to perform functions only on the visible numbers in a column. I have sorted the column so that only certain numbers are visible. I want to average these visible numbers, but numbers is averaging all of the numbers in the column, even the hidden ones. Any help?

    5|=vv,
    sum in other programs doesn't work this way either, they tend to use the subtotal function with an argument telling it the function to perform on a filtered list. (Yes, I just double checked myself).
    Its not that Numbers doesn't do it correct. It is doing it the same way every other program does it. For consistancy.
    We are missing the subtotal function that everyone is used to M$ programs adding for you when a filtered list is detected.
    Jason

  • Make movieclip visible for a specific time duration

    Is there any possibility to make a movieclip visible for a specific time (e.g. 5sec.)? I want to make "srch275" show for 5 seconds and then make it disapear. Can this be achived?
    sruch_btn.onRelease = function () {
    if (cosearchbx.text == "APPLE"){
    srch275._visible = true;

    use setTimeout():
    sruch_btn.onRelease = function () {
    if (cosearchbx.text == "APPLE"){
    clearTimeout(srch275TO);
    srch275TO=setTimeout(srch275F,5000);
    srch275._visible = true;
    function srch275F(){
    srch275._visible=false;

  • How do I set a Phase Listener to only run for a specific page?

    How do I set a Phase Listener to only run for a specific page?
    I understand that a Phase Listener runs for ever page in the application, however I want a phase listener to only run for one page at the beginning of the application.
    I discovered I can't use a Filter, because the JSF Application instance always returns null.
    Thus, I thought a Phase Listener would be a good approach.
    Thoughts?
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I have moved forward with checking the requested URI...
    (shivers)
    Thanks,
    --Todd                                                                                                                                                                                   

  • How do I save as a pdf while in acrobat cloud?  the "save as" function only lets me save as a complete webpage or html

    how do I save as a pdf while in acrobat cloud?  the "save as" function only lets me save as a complete webpage or html

    What application are you using?
    Acrobat's Save As has 21 choices available.
    Be well...

  • WAD : Call Javascript Function only on Initial Load

    Hi
    I need to replicate the functionality found in the web template parameter ACTION_BEFORE_FIRST_RENDERING in a Javascript function. I need to to do this in order to read a querystring parameter, and then perform actions based on that querystring parameter.
    Is there a way to either call a function from the ACTION_BEFORE_FIRST_RENDERING command, or how do I call my Javascript function only the 1st time the page is loaded?
    I can call the Javascript function from the body onLoad event, but that results in the function being called every time the page loads, which is not what I want ... I only want the function called the 1st time the page is loaded.
    Cheers,
    Andrew

    Seems you can use this parameter to check :
    sapbi_page.m_requestIdValue
    The first time a page is loaded, that value is 1. Thereafter, it increases. I can therefore put that check in my onLoad function, and call the stuff I need if it is 1, otherwise leave the function.
    Cheers,
    Andrew

  • To More Specific Class & Plugin Architecture

    Hello there,
    I have a plugin architecture and I want to load a particular class on demand, when a user clicks a button etc.
    I can do this using 'Get LV Class Default Value.vi' knowing the path of the .lvclass file, and I can then use the 'To More Specific Class' vi to cast it from type LV Object to the specific class I know it to be.
    However if I have 30 different classes with this method I would have to have 30 different class constants in a case structure so I can cast to the right one.  This works but it means all the classes are loaded into memory when the program is run, even though the user may never want to use most of them, which is a waste of time/memory.
    Is there a better way of doing this please?
    Thanks,
    Martin

    I wonder if minute 4:00 in Michael's video will help you. It avoids the constants, as long as all the classes are descendants of a common class:
    http://vishots.com/005-visv-labview-class-factory-pattern/

  • To find Custom Developed Function Module -Belonging to a Development Class

    Hi Experts,
    How to find custom developed function modules belong to a particular development class.
    Or Funtion Group belonging to a particular development class.
    Thanks in Advance,
    Regards,
    IFF

    Hi,
    Ofcourse you can get function group or function module associated with a Development class from Transaction SE80 or SE84.
    Step-by-step.
    1. From SAP start call transaction se84.
    2. Expand Program Library
    3. Select Function Group or Function Module
    4. In the standard selections give the 'Package' as the name of your development class.
    You will get the list of all function modules associated with your development class. The function modules starts with 'Z' or 'Y' will be the custom developed ones.
    Regards,
    Renjith Michael.

  • Email function only allows log on by email address

    The Email function only allows an email address to be used as the log on.
    My ISP's email system uses a single word hostname, therefore I cannot set up an email account with valid SMTP log on credentials.
    This is obviously OK for systems like GMail, where xyz@gmail is used together with a password but there are many systems that require just xyz and a password.

    Hi,
    The fix for this bug, might fix the issue you have.
    NX-OS 5.2(6b) Release Notes
    http://www.cisco.com/en/US/docs/switches/datacenter/mds9000/sw/5_2/release/notes/nx-os/mds_nxos_rn_526b.html#wp916553
    CSCuc03438
    Symptom: The first SSH login on a Cisco MDS 9100 or 9200 Series switch always fails.
    Workaround: This issue is resolved
    Regards,
    David.

  • Back posting only possible with same valuation class

    Hii, I made changes in valuation class before that i closed all the open po and maintained stock zero using 201 mvt type on 31st March. Now the system is throwing error when Im doing the reversal using MB1A 202 mvt type like "Back posting only possible with same valuation class". But its taking if I take the Posting date to 1st April, and we want to post on the 31st MArch. Please provide the suggestion.
    Thanks,
    Manoj

    System is behaving correctly..
    Suppose you have changed the valuation class from X to Y as on 31.03.2014.
    So your valuation class was X as on 31.03.2014.
    But now your valuation class is changed as Y. and system will always try to post the valuation class Y for material.
    So when you are trying to reverse the entry on 31.03.2014, system shows the error..
    In that case, you should change the valuation class as on 30.03.2014 and you should do 201 movement type as on 30.03.2014, and then as on 31.03.2014, you can reverse the entry..
    Now you have to reverse the 201 movement type after date 31.03.2014.
    Regards
    Dev

Maybe you are looking for

  • Infotypes and Payroll

    Hi,     Customer does not want to give display authorization for few fields in the infotypes how to resolve this issue?     To implement sap payroll what are the mandatory modules for HR ?     How do you transfer data from PA to PD ? regards, kumar

  • JBO Exception 29000 - Internal problem - attr indices mismatch

    Hello guys! Can somebody help me with this problem? Thanks in advance, Murilo Woigt JBO-30003: The application pool (myapplication.precificacao.services.PrecificacaoServices9iAS) failed to checkout an application module due to the following exception

  • Switch through list one application to another

    Hi, i have created four application in workspace and all have same user_id password for login. now i have created a list in new application this list has 3 option ,these 3 optios are differenet applications home page. after click on this link particu

  • Third part sales order

    hi all, For third party orders, if the main item is having sub item, and whether the system pass the sub item to the purchase requisition? Or not? i will be greatful if you give the answer. thanks and regards M.Ravi

  • LVM error when attempting to navigate to Operations

    When I attempt to browse to Operations in LVM, I get the following error. On further investigation, it looks like I am missing a module: com.sap.security.core.server.csi.XSSEncoder.encodeURL -This file doesn't exist.  Where can I find this module? 50