General Question: What is so bad about public members?

Hello
In many books the authors mention that using public member variables is generally a bad idea and that getter and setter methods should be used instead.
I don't see the advantage in this. As long as the getter and setter methods don't do anything else than return and set the value of an variable, how can it be better to access them by methods instead of directly accessing the field? Using methods means always more code to write.
Can anyone explain me what's the advantages of getter and setter methods?
Some code to illustrate what I mean:
This is supposed to be bad:
class Person {
  public int age;
}And should be replaced by this:
class Person {
  private int age;
  public int getAge() {
     return age;
   public void setAge(int age) {
     this.age = age;
}

duffymo said
While all of jschell's points are well taken, I think
the previous comments listing situations where data
members should not be made public are still valid.dhall said
Objects with value semantics should generally be
immutable (which brings up a whole other debate).The above two points were how the Value Object Pattern stated it.
Both of those have a certain place and are certainly appropriate for some objects (and some designs.) The DTO pattern no longer requires that. Probably for the same reason that I stopped doing the same thing years ago - it is inconvenient and doesn't pay off in terms of maintenance. Sometimes it actually does help, but most of the time it doesn't. And because of that the extra code gets in the way.
My usual pattern these days is to make the attributes public and also provide convienence methods which might consist of any or all of the following...
- A getter and setter (some people like them and since I generate all the DTOs adding more methods is trivial.)
- Conversion methods (set a date attribute using a fixed format date string)
- toString(), used for log/trace
- Validation method (usually a single method) that does the following...
----- Field validation, like validate a required field has a value, validate a telephone number has the correct format (length, etc)
----- Simple record validation, like if the telephone number field is set then the type of telephone number field is also set.
Notice that the above does not require any interaction with other signficant objects. And the above also exist solely as convenienence methods that could just as easily be placed in another helper class.
An example of what a DTO should not do is when a customer DTO verifies the account number exists when the account number field is set. This could certainly be a required validation test. But such a validation requires a level of complexity that exceeds the intent of a DTO.
I don't think it ever comes down to getters/setters
the only way OR the source of all evil. Each case has
to be judged on its own merits. The important thing
is to understand both sides of the issue and to be
aware of the consequences.
Except for the case I made above - although I didn't explain it well enough.
If most of the classes in the system have getters and setters then one of two things is true.
- They are not being used, so they shouldn't exist.
- They are being used, so something is wrong with the design.

Similar Messages

  • What's So Bad About It?

    What's so bad about iPod Linux. I am thinking of getting it but it doesn't support Nano but I will risk it anyway. Before I do please explain to me why everyone on this forum despises it.
    -confused

    I would strongly recommend to stay clear of Linux for the iPod, for the following reasons.
    1) iPod Linux voids the Apple warranty, so if anything went wrong (which frequently happens), you would have to fork out to get a repair/new iPod.
    2) Linux makes the iPod run totally differently than it used to, i.e basically making it not an iPod, but a small Linux. As Chris CA stated, "you can fill your car up with water, but it still isnt a hot-tub."
    3) Many users have reported "bricking" their iPod after installation, leaving them with a rather expensive paperweight that Apple will not touch.
    4) The Linux website also states that even they do not support Nano installations.
    5) Videos shown through Linux on a Nano are very poor quality, since its extremely difficult to get a video file small enough to fit, the screen size is tiny etc.
    6) If something went wrong, no support could be given on this forum, as it is against the Terms of Use.

  • TS3297 I forgot my security questions what do I do about this?? Plz help

    I forgot my security questions what do I do about this?? Plz help

    1. See my User Tip for some help: Some Solutions for Resetting Forgotten Security Questions: Apple Support Communities.
    2. Here are two different but direct methods:
        a. Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
        b. Call Apple Support in your country: Customer Service: Contacting Apple for support
            and service.
    3. For other queries about Apple ID see Frequently asked questions about Apple ID.
    4. Rescue email address and how to reset Apple ID security questions
    5. For online assistance use Apple - Support - Express Lane

  • Hello, my friend's ipad locked and need the apple id and password to unlock the setup and open the ipad but he don't remember any one of them nor his email and security questions what can we do about that please solution?

    hello, my friend's i pad locked and need the apple id and password to unlock the setup and open the i pad but he don't remember any one of them nor his email and security questions the serial number of tha i pad is DYT*******PH and the part number is MC979ZP/A what can we do about that please solution?
    <Edited by Host>

    Your friend will have to remember or find his account id and password, without them he won't be able to re-activate the iPad.
    Does he have any of the account's downloads in his computer's iTunes library : Recovering a forgotten iTunes Store account name.
    Or has he tried finding it via http://appleid.apple.com : Apple ID: How to find your Apple ID.
    If he can find the account id he can then get its password reset via http://iforgot.apple.com
    (As these are user-to-user forums, you're not talking to iTunes Support nor Apple, I've asked the hosts to remove the serial number from your post.)

  • What's so bad about Firefox 3.6.28?

    I'm feeling a bit Push-Shopped to buy a new computer here. . . apparently Firefox's recent upgrades don't work best on a G4 Power PC chip.
    So the solution is to run the old Firefox or find a more accomodating browser!
    My minimac works perfectly, runs well and does even more than I ask, or need, it to do! Buying new hardware seems the extreme solution here.
    So what's bad about running the older Firefox version?

    You can download TenFourFoxG5 from here:
    http://www.floodgap.com/software/tenfourfox/
    Now for the intersting bit: TenFourFox, like Firefox, does not support most plug-ins. Unless you are prone to headaches (in which case don't) you can read about that here:
    http://code.google.com/p/tenfourfox/wiki/PluginsNoLongerSupported
    But there is a workaround!
    Open TenFourFox and type in the address bar: about:config (no spaces) and click return. This gives you a warning that it might harm the application. Ignore that and click on 'I'll be careful, I promise' and you get the config file that you can edit - with great care.
    Look/search (scroll down) for: tenfourfox.plugins.enabled
    Set it to true. (Double click it to toggle it)
    Now close TenFourFox, open it again, and Flash will now work, as it now uses the plug-ins that Safari has stored.
    I am using Flash 10.1.102.64 in TenFourFox and it works just fine.

  • So what's so bad about servercache?

    Excuse how brief this post is, the forum decided to boot me
    out mid posting and I lost everything I had written. Long story
    short, why does the API reference say it's "bad" to use
    type='servercache' with the <cfcache> tag?

    I was just curious since there was no explanation behind the
    warning. I'm working on a very slow server that hosts a very big
    website, and it likes to time out during anything more complicated
    than a simple query. I've been using my own caching routines using
    wddx but cfcache looks attractive as a one size fits all solution.
    I'm more interested in the server side caching because the problems
    occur when users try to access the server when it's already bogged
    down and it times out. With things cached thanks to previous
    visitors things just pop right into place.

  • General question: what kind of error is this

    This has happened to me a couple times now. I'm in Apple Motion, working on projects that aren't too intensive, when everything but the mouse freezes. I can still move it around but I can't click on anything or change applications (not even with the keyboard). I hesitate to call this a "crash" since the app doesn't quit and the computer doesn't completely lock up. Would you call this a freeze, kernel panic, what?
    This may be related to using a Matrox MXO device with my video card, as it was turned on in both cases. Trying to work with their tech support to figure out if this is the culprit...

    Oh yes, the Console log. I know it well.
    Here's what I found in system.log at the time of the freeze:
    ATIRadeon::waitfor_rbspace: Overflowed block waiting for FIFO space. Have 2, need 5. RBBM_STATUS 0xb803c100
    ** ASIC Hang Log Start **
    (followed by lots of kernel messages)
    So yeah, definitely a graphics card issue, although maybe not the Matrox? Hard to say.
    I've had this setup (ATI Radeon x1900, Dual Apple 23" monitors, Matrox MXO) for a couple months now and it was running great under Tiger 10.4.11. It wasn't until I installed Leopard that this started happening. FWIW, I didn't upgrade, I installed it on a brand new drive that's in drive slot #4, ran all the system and Quicktime updates afterwards. Everything seems to run OK except for this occasional glitch. I ran First Aid and Repaired permission afterwards but I do regular maintenance anyway so I don't think that's going to fix anything.

  • General Questions about BI

    Hello,
    I want to get into SAP BI and have some questions about it.
    Is there a big downside in installing only the BI components without the Java BI components, or is it even possible if you want to work with BI. What are the general differences between BI and Java BI?
    I think the main aspects i will work with will be data warehousing and some basic reporting.
    The reason why i'm asking is that i want to run the BI components in the same system as the ECC Server (its just a test system). I read that the Java BI component needs EPC and EP and that would probably be too much for a single system (6 GB RAM).
    Thanks a lot in advance,
    Martin

    Thanks for your hints, they were really helpful.
    As i mentioned i mainly want to work with the general Data Warehouse and Reporting capabilities, so i think it should be okay.
    Actually i'm planing to write about BI and SAP within my master thesis.
    Another question, what will be with SAP BI in the future regarding the Business Object acquisition? Is there still any point in learning SAP BI or will SAP BI disapear in the future? I heard that the basic BI functionality (e.g. Datawarehouse ) will still be used but the reporting capabilities  would be disappear. I'm not sure if that is right and i'm really new to this topic. So any comments are welcome.
    Thanks,
    Martin

  • Asking general questions about 'computing' matters.

    Hello
    I'm new to the Mac world - I posted my first question on the forums today!
    I have reviewed the discussions site - everything seems very specific to apple products. Where, if anywhere, could I post a general question - like this one:-
    I have a notion that when one connects to a server directly (Usenet newsgroups for example) one makes a deliberate 'hole' in one's firewall, be it software or simply because one is using a NAT router. Sending messages to and receiving posts from Usenet is far quicker than using email, so I'm fairly confident that this is so.
    I am well aware that any URL one visits can instantly determine much information about the connecting machine. (see http://www.browserreport.com/ as an example).
    Anti-malware programs can only detect known viruses and spyware - I see no reason at all why, once one has granted a direct connection facility, between a group on a private server to
    one's own machine, malware could not relatively simply be injected onto one's computer.
    If the malware was currently unknown, how would one ever know?
    Thanks in anticipation of a helpful response
    David B

    HunterBD wrote:
    I'm new to the Mac world - I posted my first question on the forums today!
    Excellent!
    I have reviewed the discussions site - everything seems very specific to apple products. Where, if anywhere, could I post a general question - like this one:-
    Unfortunately, not in this forum. This forum is specifically about the discussion forum itself. It is kind of like a meta-forum. Hopefully, the moderators will just move your post somewhere more appropriate. (As indeed they just did!)
    I have a notion that when one connects to a server directly (Usenet newsgroups for example) one makes a deliberate 'hole' in one's firewall, be it software or simply because one is using a NAT router.
    Kind of and kind of not. Firewalls are greatly misunderstood. But essentially, yes, any internet connection you establish has some risk involved. However, the risk of making an outgoing connection is infinitesimally smaller than setting up a server to let hackers bang on 24x7.
    Sending messages to and receiving posts from Usenet is far quicker than using email, so I'm fairly confident that this is so.
    Really? I don't think so.
    I am well aware that any URL one visits can instantly determine much information about the connecting machine. (see http://www.browserreport.com/ as an example).
    Not really. It depends on what you are doing. You always give away your IP address, unless you are behind a proxy. In that case, you give away the proxy's IP address. But the proxy still knows who you really are.
    If the protocol in question supports such information, then it can be determined. A web browser does send some information about you, but you can easily change it and masquerade as some other browser. With other protocols, it isn't so easy to tell what kind of OS or software is being used.
    Anti-malware programs can only detect known viruses and spyware - I see no reason at all why, once one has granted a direct connection facility, between a group on a private server to
    one's own machine, malware could not relatively simply be injected onto one's computer.
    If the malware was currently unknown, how would one ever know?
    You wouldn't
    Don't grant anyone direct connection to your machine.

  • General question about iTunes Match and multiple libraries

    Hello to everyone,
    I have a general question about the iTunes Match service, which is available since yesterday in my country (Italy). Currently my library situation is the following:
    Computer A (desktop, Windows 7): "big" iTunes library (about 20 GB), at the moment not associated with my Apple ID
    Computer B (MacBook Air 2011): "small" iTunes library (about 5 GB), associated with my Apple ID
    At the moment, both my iOS devices (iPhone 4 and iPad 2) are synchronized with the smaller library on the MacBook Air.
    Question is as follows: should I subscribe to iTunes Match, would it be possible to upload the "big" library (provided I associate it with my Apple ID) to iCloud while keeping my devices synchronized with the "small" one?
    Ideally, at the end of the day, the situation should be the following: both iOS devices with music from the small library + possibility of downloading songs from iCloud (coming from the big one). Is this possible?
    Maybe the question sounds stupid, but I want to be sure about this before paying for the service.
    Thanks a lot.

    Yes, you could also associate your larger library with iTunes match if you associated your Apple ID with it. However any purchases in the library made from another Apple ID will not be matched with iTunes much.
    If both libraries are part of iTunes match, then all your devices will see all of the content from both libraries, which content you choose to have on those devices and which you have accessible via iTunes match is entirely up to you.

  • What is the provisioning feature in the settings under, general profile? It says something about "provisioning". What does that mean and what does it do?? (It's on my 5th generation iPod touch, black, iOS 6.1.3

    What is the provisioning feature in the settings under, general>profile? It says something about "provisioning". What does that mean and what does it do?? (It's on my 5th generation iPod touch, black, iOS 6.1.3

    A profile is used on iOS device to add specific settings and similar things to an iOS device.  Tryically, they are added when the iOS devices is controlled by a company or school.
    However, some apps install a profile. If your iPod is not controlled by a company or school then it seems an app added the profile. You can good the title if the profile and see if that gives any info.

  • General question about converting...

    Hi,
    I'm kinda new to editing and I'm working on a project here using PP CS3 and a lot of footage in .vob file format.
    I've read some posts in this forum, and I know that a lot of people have problems importing .vob files and that a lot of users recommend using Premiere Elements.
    Now that is for a few reasons not an option for me, and I've kinda had a good expercience importing .vob files via the Avisynth method, which really works perfectly (no red frames, etc.) - BUT PP starts crashing when exporting a project bigger than 2-3 min using those .vob files...
    That does not happen when I use .avi (or other) footage...
    I've read in other posts that people recommend converting the .vob files to (uncompressed) .avi - and I tried that, but it seems to me - just looking at the footage - that the quality is slightly worse...
    Is that in general the case, that you loose quality when converting to .avi (or maybe converting in general) ?
    What output format would you recommend converting to (from .vob) when trying to keep the quality but getting a smaller file size than uncompressed .avi ?
    Btw, I use Carbon Coder for converting the footage...
    Thanx for your help in advance !
    Mike

    Harm,
    thanx for your reply.
    The footage was given to me in .vob file format, so I can't play it through the camera...
    And coming back to the Apple Juice ;), I know that the quality did already take a hit that's why I'm (desperately) trying to keep the quality we have to start with...
    What about converting to .avi using the HuffYUV codec (read that in another post)?
    Mike

  • Newbie question - general question about e-mail sync

    Hi,
    I have a general question about email sync and BlackBerry smartphones.  Are there any devices that allow email syncing with a Microsoft Exchange 2007 system that do not require the BlackBerry Enterprise server?
    Thanks; sorry if this has been asked before but I was unable to find it in the forums, documentation, etc.  Everything I found assumes that for this kind of environment you will be using a BlackBerry Enterprise solution, but I can't assume.
    Thanks again.
    Solved!
    Go to Solution.

    Hi and Welcome to the Forums!
    If the Exchange server has anything that faces the internet (OWA, POP, IMAP), then BIS can be used to handle email (only email...calendar and contacts require BES to sync OTA).
    Or, a PC, inside the network (but with an internet path) and logged into the email server (using Outlook), can be left running, using the RIM Desktop Software's Desktop Redirector capability to forward  messages to the BB.
    Those are basically the options.
    Hope that helps! Let us know!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • I am trying to reset my password questions and it keeps sending it to the wrong email. what do I do about it?

    Please Help me.

    Forgotten Security Questions/Answers
    You need to contact Apple by:
    1 - Use the Express lane and start here:
    https://expresslane.apple.com
    then click More Products and Services>Apple ID>Other Apple ID Topics>Forgotten Apple ID security questions.
    or
    Apple - Support -form iTunes Store - Contact Us
    2 - Call Apple in your country by getting the number from here:
    http://support.apple.com/kb/HE57
    or           
    Apple ID: Contacting Apple for help with Apple ID account security
    3 - Use your rescue email address if you set one up
    Rescue email address and how to reset Apple ID security questions
    For general  information see:
    Apple ID: All about Apple ID security questions

  • Round trip workflow with proxies between Premiere and AE / a more general question about how these programs work?

    Hi all,
    I'm new to editing with proxies in Premiere and have some questions about how to handle the relationship with After Effects. Say I have a rough cut (with proxies) and I want to send it to AE to do some effects. The simplest thing to do seems to be to replace the proxies with the originals in Premiere, send the project to AE and do my thing. But if I then want to send the project back to Premiere, it will involve the original files, which are too machine-intensive for me to edit. In theory, it seems like there should be a way to send the project with original footage to AE, do effects, send it back to Premiere, and then replace it with proxies to do further editing while retaining the effects.
    This leads to a confusion about how AE works. When I do an effect, am I correct in assuming that it does nothing to the original file? If that's the case, it seems like it shouldn't matter (in the editing stage) what file AE "applies" an effect to (proxy or original). But I feel like there's a hitch in this workflow. The same question could also be asked about going back and forth in Speed Grade.
    Perhaps there is no real answer to this and the best option is to save effects and grading for after I have picture lock, but sometimes that's not entirely possible or convenient, etc.
    Hopefully this makes some sense—It's a little hard to explain.
    Thanks.

    Hi Mark,
    Here are the specific sections of the manual that should give you the best explanation regarding the Check out/in workflow for FCP projects in Final Cut Server:
    Check out:
    http://documentation.apple.com/en/finalcutserver/usermanual/#chapter=7%26section =5
    Editing:
    http://documentation.apple.com/en/finalcutserver/usermanual/#chapter=7%26section =6
    Check in:
    http://documentation.apple.com/en/finalcutserver/usermanual/#chapter=7%26section =7
    -Daniel

Maybe you are looking for

  • Error on invoking a siebel wsdl using bpel

    Hi, We are getting the following error on trying to invoke a siebel application wsdl through bpel: exception on JaxRpc invoke: HTTP transport error: javax.xml.soap.SOAPException: java.security.PrivilegedActionException: oracle.j2ee.ws.saaj.ContentTyp

  • How can I design and send emailers using Adobe Muse?

    Hello Geeks, How can I design and send emailers using this wonderful software called Adobe Muse?

  • Deploying printers with gpp cse to computers and setting the default printer results in this error

    The computer printername preference item in the 'Printer deployment' Group Policy object did not apply because it failed with error code '0x80070709 The printer name is invalid.' This error was suppressed. I've read that this is a timing issue does a

  • Sort of baffled - looking for clarity

    Hello. I have a 10 minute QT movie that I created a while ago in FCE 4. It is 1920 x 1080i HD in size. I was looking for an easy way to export this in ONE size/format that will work with both my iphone and my new Apple TV. I tried using Handbrake to

  • HT5312 How do you set up a rescue email?

    I just got a new IPhone, but before I can make purchases on it I ha r to answer my security questions, which I forgot the answers to. To reset the questions I have to get an email sent to my rescue email. But I don't have a rescue email. I already ha