OOP Q about whether getters can really be avoided

This is a general OOP question.
There is a ClassA with a private instance variable consisting of an array of ClassB objects. ClassB has a private instance variable x. ClassA objects need to know something about the value of x for their array of ClassB objects; e.g x might be an int, and ClassA objects might need to know the sum over their ClassB objects of ClassB.x. How should this be done?
An obvious approach is to define a getter in ClassB that returns the value of ClassB.x and have a method in ClassA that computes the sum. But this seems to violate encapsulation, because if the type of x is later changed, then the method in ClassA has to be changed as well, because it's expecting a certain return type from the getter. Having ClassB compute the sum doesn't solve the problem either, because the type of the sum depends on the type of x, so any method in ClassA that gets the sum from ClassB is vulnerable to a change in the type of x.
This seems like a fairly common situation - how should it be handled?
Thanks,
Mark

In the absence of other constraints, do whatever takes the least work at the time.
In the abstract case you give, there's no driver one way or the other.
It's quite natural that an OrderItem might have a cost, and something want to look at the cost and total it with an exterior sum.
It's quite natural that a RocketBooster might contribute thrust to a ThrustTotal and so use an interior sum.

Similar Messages

  • I want to ask about changing perspective and perspective correction in photoshop. Obviously, we can tilt and straighten buildings and other monuments, which are leaning in any direction. Now, what I want to know is whether we can change perspective for hu

    I want to ask about changing perspective and perspective correction in photoshop. Obviously, we can tilt and straighten buildings and other monuments, which are leaning in any direction. Now, what I want to know is whether we can change perspective for human faces. For example, if there is a human face, where one part of the face is facing the camera and the other part of the face is only partially facing the camera, can we make this face look totally at the camera? I mean, look straight in front, and I am talking about the whole face here. I am attaching an image as an example of what I am talking about. @

    If you are wondering why you are not getting any responses, it is because you have vented a complaint without any details that make any sense or give anyone something to work on.
    If you want help, I suggest actually detailing what has happened, with versions of software etc. Anything that would let us assist.
    As a start I am guessing that you have not really got the hang of "How it all works". Firstly download the Pages09_UserGuide.pdf from under the Help menu. Read that and view the Video Tutorials in the same place. A good addition would be the iWork 09 Missing manual book and something to help you learn how to use your Mac.
    If there are specific tasks you need help with:
    http://www.freeforum101.com/iworktipsntrick/index.php?mforum=iworktipsntrick
    Is a good resource.
    Peter

  • Because, I will depart from Australia in 17/11, the recipient time of my order(iphone4s) is about 16/11. I am worried whether I can get my item here. Can you deliver my item earlier?

    Dear apple staff
    I will depart from Australia to China in 17/11, but my order will be deliver  25/10--2/11, and the shiptransport will take 1-2weeks. I am really worrid whether I can get my item before I leave. I have a little request that can apple deliver my item  a bit earlier than 25/10. A big thank to you.\
                                                                                                   best wish to apple and Jobs!
                                                                                                                                                     your loyal customer Wen jie Ma
                                                                                                                                                                             16/10/2010

    There is no Apple staff here, only users like yourself.
    Pick up the phone and call them.

  • HT1539 I downloaded my digital copy of Star Trek Into Darkness, but it's HD and I can't play it. I didn't see anything about whether I wanted HD or Standard. How do I get this changed?

    I downloaded my digital copy of Star Trek Into Darkness, but it's HD and I can't play it. I didn't see anything about whether I wanted HD or Standard. How do I get this changed?

    Check the mute switch on the side above the volume rocker. If the red dot shows, the phone is muted. You'll still be able to play the ringtones to select one.
    I find that the switch can be thrown to "mute" by accident when I put my iPhone in my belt holster.

  • Whether it can be implemented about idocs?

    whether idocs can be parsed by non-sap program without connecting to SAP system?
    Message was edited by: Leslie Zhu

    Leslie,
    to partially answer your question:
    If the IDOC is in a java object or XML or fileformat that survives outside of the SAP environment then why would you not be able to parse it? So the answer to the question with these parameters is yes, you can parse it without a connection to SAP.
    Or does your question actually refer to the JCO.IDoc classes, if they can parse IDOC's without a connection to SAP? Don't know, but I am sure that someone else has tried this out.
    Cheers,
    Kalle

  • I'm investigating whether I can take on 'Lion' when it's released. The information states that your mac needs Intel Core 2 Duo. Is this the same as '2 GHz Intel Core Duo' which is what it actually states my mac has?

    I'm investigating whether I can take on 'Lion' when it's released. The information states that your mac needs 'Intel Core 2 Duo'. Is this the same as '2 GHz Intel Core Duo' which is what it actually states my mac has when I click 'About This Mac'?

    I could not agree more! My MBP 2007 Intel Core Duo has had its logic board replaced not to long ago (DVI port died). The original hard drive is running great and I am running Snow Leopard wonderfully.
    I was amped during the keynote and am really looking forward to Lion. I know the community is working hard to uncover a workaround because at present time, the solution (by new!) is not a worthy one. Especially when there is literally, nothing wrong with my existing machine.
    Apple, please ensure Lion will be available for Intel Core Duo machines, we are not that old! The closed architecture approach produces quality hardware. 4 years is a toddler perhaps teenager when it comes to apple hardware and technology. I predict I have at least 3-4 more years left in my current MBP 2007 machine.
    Much Love, Apple!

  • How do you send information about whether you've received and read a message on messages?

    Apparently there is a feature where you can either show or hide when you are sending information about whether you have read a message and when you are typing. Where can I access these features?

    Hi,
    You will see a checkbox for "Send Read Receipts"
    When you have the iMessages account as the Listed/highlighted Account.
    You can also Auto reply with the Away Message in any other account (Mostly AIM based)
    Go to Messages > Preferences > Messages section and tick the box at the bottom "Auto Reply with My Away Message"
    Of course you have to set an Away Setting (with or without a Messages) for it to be sent. (it is better though of you choose or create an actual message)
    9:16 PM      Sunday; September 9, 2012
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
      iMac 2.5Ghz 5i 2011 (Lion 10.7.2)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • Whether we can able to save the data in the portal side or not?

    Hi All,
        Could anyone please tell me, whether we can able to save the data in the portal side or not, if possible can you please explain the procedure.
    Thanks in advance,
    Siva.

    If you are familiar with java then you can use the usual jdbc / odbc driver to connect. Do search the forums, this has already been discussed many times before, if you encounter a road block do post back.....
    You can also refer to this blog, though it talks about CE 7.1 the concepts remain the same, the configuration screens might differ - Connecting an Application to an External Database in SAP NW CE 7.1
    Did some searhing for you refer these also
    https://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/70929198-0d36-2b10-04b8-84d90fa3df9c&overridelayout=true
    How can I set the data binding between Web Dynpro & Database table
    Connect to External Oracle Database
    Urgent : Hoe to connect to a ORACLE database throught WEBDYNPRO JAVA <-- good one
    Thanks,
    GLM
    Edited by: GLM on Aug 18, 2009 11:38 AM
    Edited by: GLM on Aug 18, 2009 11:41 AM

  • Iam from India. my brother is in new jersey. he is going to get one iphone 5s for me in t mobile contract free . I wanna know whether I can use it here as well as whether I can claim warranty here or not. pls let me know

    Iam from India. my brother is in new jersey. he is going to get one iphone 5s for me in t mobile contract free . I wanna know whether I can use it here as well as whether I can claim warranty here or not. pls let me know

    You'll have to consider the benefits; is the lack of LTE and the need to send the phone overseas (THus be without a phone for that length of time) really worth the 250$ difference you'd save?
    ME personally I'd rather fork over that amount of money and get the quality of phone I purchased, and not have it at half strength.

  • I'm getting this error statement: XULRUNNER error: platform version 6.0.2 is not compatible with min etc max etc6.0.1 - what is this about and how can it be corrected?

    This is what I think may have happened. The other day, Thursday Sept 8th, I shut down my pc in the middle of a Firefox upgrade. Now when I try to access Firefox on my pc, I get this error message:
    XULRUNNER Error: Platform version '6.0.2 is not compatible with min Version >= 6.0.1 max Version < 6.0.1
    What is this about and how can I retsore access to Firefox on my pc?

    If you use ZoneAlarm Extreme Security then try to disable Virtualization.
    Do a clean reinstall and delete the Firefox program folder.
    * http://kb.mozillazine.org/Browser_will_not_start_up#XULRunner_error_after_an_update
    *[[/questions/869812]]
    *[[/questions/869951]]

  • I am using an iPad and iPhone and have exchange as my email. Both will only collect mails when I am in the wifi of the office, and not when I am out and about. I can't seem to get a fix for it.

    I am using an iPad and iPhone and have exchange as my email. Both will only collect mails when I am in the wifi of the office, and not when I am out and about. I can't seem to get a fix for it.

    This - https://support.mozilla.org/en-US/kb/how-make-web-links-open-firefox-default - didn't work?

  • My computer is saying it can't find the file 'iTunes64.msi' when I try to update or redownload iTunes how do I fix this? I've tried just about everything I can think of. I am using a dell laptop running windows 7 and have tried changing the file loca

    My computer is saying it can't find the file 'iTunes64.msi' when I try to update or redownload iTunes how do I fix this? I've tried just about everything I can think of. I am using a dell laptop running windows 7 and have tried changing the file location to run the update in all of my iTunes files as well as when I've tried reinstalling it.

    For general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down the page in case one of them applies.
    The further information area has direct links to the current and recent builds in case you have problems downloading, need to revert to an older version or want to try the iTunes for Windows (64-bit - for older video cards) release as a workaround for installation or performance issues, or compatibility with QuickTime or third party software.
    Your library should be unaffected by these steps but there are also links to backup and recovery advice should it be needed.
    tt2

  • How can i add videos,movies and tv shows episodes to my ipod nano?I want to know whether i can directly add them through my pc or not without downloading them from i tunes store?

    how can i add videos,movies and tv shows episodes to my ipod nano?I want to know whether i can directly add them through my pc or not without downloading them from i tunes store?

    Yes, you can add your own videos to iTunes, then sync them to your nano, subject to supported max resolution limit and file type.  The specs for the 7th gen nano says (I don't know which nano model you have), Video Format Support
    "H.264 video: 720 by 576 pixels, 30 frames per second; Baseline, Main, and High-Profile level 3.0 with AAC-LC audio up to 256 Kbps; 48kHz; stereo audio in .m4v, .mp4, and .mov file formats
    MPEG-4 video: up to 2.5 Mbps, 720 by 576 pixels, 30 frames per second; Simple Profile with AAC-LC audio up to 256 Kbps; 48kHz; stereo audio in .m4v, .mp4, and .mov file formats"
    http://www.apple.com/ipod-nano/specs.html
    (earlier nanos have lower max resolution limits)
    So, "HD" video is too high resolution, so iTunes will not sync such videos to the iPod (although they play in iTunes).  If you are asking how to set up iTunes to sync videos in general (regardless of source), please post back.

  • I currently run the Design and Web Premium CS6 on a first generation MacBook Air and want to buy a new MacBook Pro. How do I know whether I can install my Adobe programs onto the new computer? Because I know there is some kind of limit.

    I currently run the Design and Web Premium CS6 on a first generation MacBook Air and want to buy a new MacBook Pro. How do I know whether I can install my Adobe programs onto the new computer? Because I know there is some kind of limit.
    Also, I had to install the software twice on my same computer before because I had to reboot the computer. I don't know if this affects the limit.

    You are allowed to have two activated installations so there should not be a problem having working installations on the two machines.  If by chance you have somehow tied up two activations for the one machine you can have Adobe support help resolve that thru chat.
    Serial number and activation chat support (non-CC)
    http://helpx.adobe.com/x-productkb/global/service1.html ( http://adobe.ly/1aYjbSC )

  • My itunes is playing up. every time I play a track or album I get a crackling interference noise. What's this all about and how can I stop it?

    my itunes is playing up. Every time I play a track or album I get a crackling interference noise.  It sometimes abates for a while but then comes right back again!What's this all about and how can I stop it?

    See if this article will help:
    iTunes and QuickTime for Windows: Audio does not play or plays incorrectly
    http://support.apple.com/kb/TS1362

Maybe you are looking for

  • PLEASE HELP ME INSTALL HP ENVY 7640 SERIES WITHOUT DISC

    can't locate disc.

  • IPod 30 GB, HELP

    I have downloaded 317 songs to my iPod. These songs have used 6 GB of memory. Why is that? I copied my CDs into iTunes. Please help!! At this rate, I will be lucky if I get 1500 songs in a 30 GB iPod.

  • About selection screens

    we define a user defined selection screen in one program 'x'.Can we call it in another program 'Y'? and Why?

  • Does it have a way to get PublicKey as a String

    I want to implement RSA in java and javascript. But it seems there is no way to receive a public key as a String in Java API (cause i need to use the key in javascript at client side) I want to know whether this implementation is possible or not. Thx

  • Names of the software required ?

    Hello, I've recently attended a seminar on how Oracle can be used to do ecommerce. According to what I learned now we require the following software: Oracle 8i database Oracel 9i AS and also something I thought was called IDS ? which contains 6 compo