Hard to Write Good Getters/Setters

I am thinking about writing a complex wrapper to set and get any floats/strings/ints. Cause hate how OBJ-C handles these references/values and having to deal with headers and main files everytime something changes is a real big headache. On top I hate having to decide if your instance variable should be handled like a reference (which can be shared) or a value (which cannot). Most of the time you want value semantics, but implementation efficiency often makes folks choose reference semantics. Your decision effects how you write your getters/setters. Had to figure this out for myself, as I never found any good explanation of it.
Not only do you have to deal with the reference/value semantics issue, but reference counting, threading and exceptions also complicate the issue.
I am should just write a class to handle all this junk and use the #import so I dont have so much incredible redundant code that OBJ-C somehow needs.
my plan:
MyClass.SetInt(intname, x);
SetInt, this will overwrite/declare an existing int variable by that name held in the class.
x = MyClass.GetInt(intname);
GetInt, this retrieves an existing int variable by that name held in the class - or returns nil if undeclared.
but this is all fantasy, still .... I just might try it.

well, i've been asked to do it.
I'll make a short overview : I have a program that creates an XML file with some information about a workflow diagram. The company that requires this software wants to get the execution trace that create the XML file, apart from the XML itself, so they can freely modify it without the need of using my app. My app uses their libraries to write the XML. They could overwrite the XML directly but they already got the libraries and the parser to access each element.
So, they want the execution trace of the code that generates the XML.I think you're going to be far better off inserting logging statements into your code, and building a small self-contained example from the output of those statements.
If you don't want to do that, and are comfortable with JNI, you can write a trace agent using JVMTI
Or, you can use aspect-oriented programming to add cutpoints to their methods, with a tool such as [Aspect-J|http://www.eclipse.org/aspectj/]
There's also a "trace" command in JDB. Haven't used it, so can't tell you whether it will tell you everything you need.
And there used to be a tracing interface that could be accessed from Java code. At least I seem to remember writing a trace utility in Java. Could be that it's available on the JRockit JVM and not Sun.

Similar Messages

  • Getters & Setters in ABAP?

    In C# and in Java we have special functions that operate on private class data called getters and setters.  These are almost always public and allow the "outside" to interact safely with the private class data.  An example would be :
    [C#]
    public class Vehicle
         private string _make;
         private string _model;
         public string Make { get { return _make; } set { _make = value; } }
         public string Model { get { return _model; } set { _model = value; } }
    [Java]
    public class Vehicle
         private string _make;
         private string _model;
         public string getMake() { return _make; }
         pubic string setMake(string value) { _make = value; }
         public string getModel() { return _ model; }
         public string setModel(string value) { _model = value; }
    This allows controlled access to the private data (_make and _model).  For instance, I can put rules into the setters that makes sure the data is valid that's coming in from the outside, or in both the setter and getter that checks the user's permissions to see if they have the right to access this data.  It's simply a way to implement "encapsulation".
    Does ABAP use getters/setters?  If so, are they implemented as in Java or does ABAP have its own implementation?
    Thanks!

    No reason to be sorry, I understand that you simply didn't know.    Here is the run-down.  You can award points to any answers that you find helpful.  If one answer in particular has solved your problem, you then mark the radiobutton next to that answer which is blue, this gives the person 10 points.  If the answer was very helpful,  then select the green star, this is 6 points to the user, and if helpful, mark yellow star for two points.  If not helpful at all, then don't mark any.  You can also,  mark the thread as "Solved on your own".  This closes the thread by giving it a blue star, but doesn't give any points to anyone(which is what you have done to the other posts  )   It is very good that you have closed the threads, because this gives visibility that your problem was solved or your question is answered.  But awarding 10 points to the answer which solved your issue, will also close the thread.   
    You can go back and revisit your other threads and award points according.
    Help this helps, and welcome to SDN.
    Regards,
    Rich Heilman

  • HT4527 My old pc ran windows vista and mother board failed but the hard drive was good. I have a new system now and installed the old hard drive. how do I get itunes and all my music working now?

    Hello, my old pc ran vista o.s. and the mother board died but the hard drive was good. I got a new system running windows7 and installed old hard drive to recover pictures and other data. How do I get my itunes and all my music back up and running.

    See Recover your iTunes library from your iPod or iOS device.
    tt2

  • How to disable hard disk write caching?

    How to disable hard disk write caching?
    Is there something similar to Windows: http://support.microsoft.com/kb/259716/en

    Manually mount the disk, disabling the cache.  With the default mount mechanisms, no.  Details.

  • Using 'variables.instance' structure and implicit getters/setters

    I am adopting the use of creating a variables.instance (I use 'variables.my') structure to separate instance data from the object, however I have a question when it comes to ColdFusion creating implicit getters and setters based on that object's defined properties.
    BEFORE, if I had a Name property, CF would create getName() and setName() for me, and it would update the variables.Name private variable accordingly in each.  But now that my variables are being stored in 'variables.my.Name', does this mean I can no longer use ColdFusion's implicit getters and setters? (because it would improperly be attempting to execute getName and be looking for variables.Name, when that data now exists in variables.my.Name?
    Are there any methodologies around that allow me to utilize CF's implicit getters/setters while using this 'my' instance variable and have them work with one another?

    Thanks for the confirmation Carl.
    How cool, then, would it be if ColdFusion 11 supported something like:
    <cfcomponent
         accessors="true"
         implicitpropertyprefix="my."
    That way I could specify "my." as the property prefix and when it goes to create those implicit getters and settings, it will concatenate that into 'variables.my.' as the prefix when it alters property values or returns them.

  • Getters & setters

    I am a newbie and trying to learn, I have a type & service table
    type
    t_id
    t_name
    blah
    blah
    service
    s_id
    t_id (fk)
    blah
    blah
    For a Add Screen, I have Type in a text field & JTable for the service (can be multiple for one type).
    Now normally when it is recommended to have getters & setters for everything, how do i have setters for the JTable (ie corresponding to the service table).
    I don't want to basically go back and forth the database 50 times , ie do the setter, insert to db, and repeat.
    Both are in the same screen as per the UI design ? How does everyone normally does this ?
    Thanks much

    Now normally when it is recommended to have getters & setters for everything, how do i have setters for the
    JTable (ie corresponding to the service table).That is not the normal recommendation:
    If and only if there is a compelling reason to expose the value of a field member of a class, you should do so through accessor methods, as this allows additional factilities (input validation, logging, etc) to be added and the implementation details to be changed.
    So it's not 'getters and setters for everything', but rather everything that needs to be accessed outside the class should use a getter or setter.
    Is there a compelling reason why the table should be accessible outside your GUI? Normally the view (in this case your JTable + the TableModel wrapper) asks a model (your data structure holding type and table, maybe reusing the generic ones supplied by Swing, maybe not) for the data, and doesn't expose the implementation of the view (the JTable) to the outside world.
    Imagine that, instead of using JTable, you changed your GUI to use a tree where the services were shown under the types; a local implementation change like that shouldn't effect any other part of your application, so only expose the parts of your view that are unchanged by such implementation details.
    Pete

  • Sets, getters, setters, adders, iterators...

    After reading the highly interesting thread about getters and setters and their implications over OO-design, I'm wondering how to manage sets elegantly... and actually any Collection
    Let's say I have a class A that has to reference a set of objects (meaning, as everyone knows, these objects needn't be ordered and can appear only once in the collection)
    As Peter answered, I should go for getters of the like "getObject(int)" with the help of a "nbOfObjects()" method... alright... that seemed logical for ordered data structures like lists... now, how would you manage that with sets, since an indexed "get()" doesn't make much sense... as stated in the Javadoc, the Set contract doesn't guarantee that the order remains the same, so does something like this make sense ?
    class A {
       private Set set = Collections.synchronizedSet(new HashSet()); // or should I declare it as a Collection, even if I know no element should appear twice ? I suppose not...
       // Does it make sense ?
       public Object getObject(int i) {
          Object[] objectArray = set.toArray(); // called every time the user iterates further... looks like ugly overhead to me...
          return objectArray; // or objectArray[i].clone() ?
    If it DOESN'T make sense, how would you iterate over a Set ? Is returning an iterator the only way ? a clone of the collection to allow the user of the getter to use enhanced for-loop (what are its uses otherwise except for "class-internal-iterating" ?) ?
    I'm both interested and confused since I've read this thread which shakes the very foundations of my conceptions on that matter ^^
    thx a lot for any help, examples, comments or links (not too many, plz, I prefer cut&pastes, I'm out of Internet quota for this month at work :p (thank god, I had them make *.sun.com free ^^)) you could provide

    My first point is, make the set private final
    Secondly an index to a HashSet is dangerous concept
    as the order can be completely re-ordered when an
    element is added.
    A better choice would be LinkedHashSet which has a
    consistent ordering.didn't know about that class... interesting indeed :)
    >
    I would suggest that if you need to return the
    collection use Collections.unmodifable or a copy.didn't know about Collections.unmodifiableX() either... sounds great but it looks like an ugly workaround for java's lack of 'const' keyword : / throwing an UnsupportedOperationException at runtime sounds less safe than enforcing constant operations at compile time, doesn't it ?
    >
    As you have a synchronised connection, multithreading
    may be an issue. (ie the size could change while
    another thread is "iterating")
    With the HashSet reordering on an insert could mean
    the same object appearing more than once. e.g.
    appearing at the start of a list and a moment later
    at the end.
    One approach is to maintain an array when the set
    changes and return that.
    private static final String[] NO_STRINGS = new
    new String[0];
    private final Set set =
    et = Collections.synchronizedSet(new
    LinkedHashSet());
    private String[] setItems = NO_STRINGS;
    public void add(String string) {
    synchronized(set) {
    set.add(string);
    setItems = (String[])
    = (String[]) set.toArray(NO_STRINGS);
    public String[] getSet() {
    return setItems;
    Sorry but I find this solution a bit weird... updating two representations of the same data each time a piece of data's added is the kind of things I want to avoid... what's more, using synchronised collections should shield you from having to write "synchronized" all over the place IMHO... what's the point in using a synchronized collection to add to your class an unsynchronized copy ? then you'd be better off synchronizing your add method and using an unsynchronized collection... you're supposed to never access the original collection anywhere else than in its class anyway...
    what about :
    public class A {
       private final Set set = Collections.synchronizedSet(new LinkedHashSet());
       public void addToSet(Object o) {
          set.add(o); // thread-safe anyway, ain't it ?
       public Iterator getObjects() {
          Set constCollection = Collections.unmodifiableSet(set);
          return constCollection.iterator();
       // OR... (can one of the above and below constructs be considered as "better OO" than the other ? if so, why ?)
       public  Collection getObjects() {
          return Collections.unmodifiableSet(set);
    }still a bit lost, but I feel I begin to see the light... :p

  • Thunderbolt hard drives any good

    hi just been looking on the apple site and notice they have the new thunder bolt 6t hard drives
    wanted too find out if they are any good  ?  i will not be using for any sort of pro use just back ups usuall but i like the fact its super fast compare too usb 2.0 is it really that fast ? how long will take to say transfer a 10gig video file ?

    I suggest you google "thunderbolt hard drives" and research them.  Don't just look at what apple sells in there online store.  Look at reviews.

  • How to write good PHP code in dreamweaver?

    Here's the thing.  I'm using Dreamweaver CS4 to develop a website.  In the past my php files would look like this:
    <?php
        echo '<h1>Welcome ' . $name . '</h1>';
    ?>
    This caused problems in the design view because all I would see would be the php icon to let me know I have some script in this location and that is it.
    Then I started to realize that I should write my code like this:
    <h1>Welcome <?php echo $name; ?></h1>
    This second way of writing php code is a lot easier to work with in Dreamweaver since in the design view I can see the formatted h1 tag with the word 'Welcome' beside it (followed by the php icon).  I can still apply all the standard CSS rules inside Dreamweaver and the design view updates nicely.
    So now here is my issue.What is the best way to handle if statements?  Say I want to toggle between <h1>Welcome $user</h1> and <h2>Good bye</h2> BUT I would like to still be able to format the CSS and see the results on the screen in design view.  Is it possible?
    If I do the following, then I'm back to square one.  I can't see my CSS rules applied in the design view since all I have is the PHP icon to show where the script is located:
    <?php
       if( $welcome ) {
          echo '<h1>Welcome ' . $name . '</h1>';
       else {
          echo '<h2>Good bye</h2>';
    ?>

    There is another way. But it's considered advanced PHP in this community. It's called a a ternary operator. So
    <?php
       if( $welcome ) {
          echo '<h1>Welcome ' . $name . '</h1>';
       else {
          echo '<h2>Good bye</h2>';
    ?>
         woud look like:
         <?php echo($welcome?'<h1>Welcome '. $name . '</h1>' : '<h2>Good bye</h2>'); ?>
    Here's a link to a good explanation: http://www.addedbytes.com/code/ternary-conditionals/

  • Is a disk image of the whole hard drive a good way of backing up your files?

    I have to make a backup of my macbook pro because its being taken to the technician.
    I wanted to know if creating a disk image of the whole internal hard drive to an external one using disk utility is a good and secure way?
    After this I would erase my hard drive using this thread : OS X Mavericks: Erase and reinstall OS X
    Is this a good procedure? I not which one would be the best one? I read something about bootable clones but I don't seem to fully understand it and I don't know if its what im looking for.
    Your help would be awesome!
    Thanks!

    Disk Utility>Restore will copy the OSX, the Recovery Partition and ALL user data.  It will be an identical copy of the internal HDD.
    Third party software such as Carbon Copy Cloner can also perform that same function, but also allow for incremental changes.
    Ciao.

  • Generating Getters/Setters/Interface methods

    Hi All,
    Quick question, ive used Eclipse before, and in it you can generate getters and setters for your class variables
    as well if you have a class that IMPLEMENTS some interface
    it also could let you generate the methods from that interface.
    Can JES 8 do this?
    Let me know how, i am kind of tired of writing myself.
    Thank you everyone

    The getter/setter generator is accessible from the Refactoring menu, in both the main menu and the editor context menu. It is referred to as Encapsulate Fields.
    Implementing methods is available via the keyboard shortcut Ctrl-i and in the Tools menu as "Override Methods".

  • Getters/Setters controversy

    So I'm going back and forth about whether or not to use getters and setters and any alternatives if I don't. I've read some articles that say getters and setters should be avoided at all cost.
    But I have an example program here, with a class called FlightInfo which basically holds all of the flight information such as flight date and the flight number. Wouldn't it be easiest to use getters and setters like the following:
    public class FlightInfo {
            private String date;
            private int flightNumber;
            public String getDate(){
                    return date;
            public setDate(String date){
                    this.date = date;
            public int getFlightNumber(){
                    return flightNumber;
            public setFlightNumber(String flightNumber){
                    this.date = flightNumber;
    }Is there any better alternative to this? Also, the flight date may change for a particular flight number.
    Thanks.
    Edited by: java_fan_69 on Dec 5, 2007 10:33 AM

    This:
            private String date;
            private int flightNumber;
            public String getDate(){
                    return date;
            public setDate(String date){
                    this.date = date;
            public int getFlightNumber(){
                    return flightNumber;
            public setFlightNumber(String flightNumber){
                    this.date = flightNumber;
            }has the same exact effect as this:
            public String date;
            public int flightNumber;They both allow you to access and modify the variables. I tend to favor using getters and setters, even when they don't add anything a) for consistency, so I can always find what I need in the methods, and b) in case they need to change later. For instance, you want to do some check on the flightNumber before setting it, or perhaps return the date in a different format in certain conditions.

  • Help using getters & setters

    I am wanting to make a bean that will connect to a database and bring back data depending on what was entered in a html form. I have been told it would be easier if i make a bean that holds details of a single video. I have done this below, my question is in the servlet that connects to the database how will i use the result set to use these getters and setters?
    package site;
    public class vidBean
         //protected variables
         protected int recording_id;
         protected String title;
         protected String category;
         public void setRecId(int Rec)
              recording_id = Rec;
         public int getRecId()
              return recording_id;
    ... etc

    something likeList<VidBean> videos = new ArrayList<VidBean>();
    while(rs.next()) {
        VidBean video = new VidBean();
        video.setRecId(rs.getInd("id"));
        video.setTitle(rs.getString("title"));
        video.setCategory(rs.getString("category"));
    }

  • Ipod Nano sync error :  Hard disk write protected

    I have a 2nd gen IPod nano 4 GB. I had Itunes 7.1 installed on my PC when I last synced. A week later my disk crashed and in the new disk I installed Itunes 7.2. When I tried to sync, I get a error message which says " disk is write protected. Please remove write protect and sync again "
    Can someone help

    No, you can use a third party program like Yamipod, or XPlay2, etc. But I would advise you to download iTunes anyhow, even if you have to go to another computer and then burn it to a CD or something.
    12" PB, Mac Mini (x2), G3 iMac (x3), G4 iMac, G5 iMac, Centris 610, SE30, Mac+   Mac OS X (10.4.4)   3G iPod, iPod shuffle, iPod nano

  • Which ssd hard drive is good for the mac book pro 2011 early version?

    i am looking for a ssd hard disk to boost up the speed of my mac book pro 2011 early model.any suggestion for the same user here? or i should not upgrade it? if i changed it, will my warranty be compromised? thanks for answering

    best SSD's for the money: http://www.tomshardware.com/reviews/best-price-ssd,3070.html
    top 20 SSD manfacturers: http://www.storagesearch.com/ssd-top10.html

Maybe you are looking for