Should I denote that a method satisfies an interface?

When writing a class which has ("satisfies") 1 or more interfaces, should I note somehow (e.g. in an XML comment, or with an attribute) that a particular method was added for one of the interfaces?
For example, the IComparable interface requires an int
CompareTo(Object) method.
I know I don't need to do anything other than implement the appropriate methods, but for maintainability and ease of understanding are there any "best practices"
for letting others know why the method exists?

Yes. Your inclination is sound. You should leave a comment in the method's source code and/or larger documentation.
// Implements IComparable interface
in the method source should do the trick, allowing those who will be reading the code closely (you later on, or someone else maintaining, modifying, or adapting it) to easily and rapidly acertain why the method exists.
If the method is part of a promoted API, it can also be mentioned in the API docs (the form of which will vary based on what documentation system you're using).
Even if you're not fully committed to literate programming, in which
an explanation of the code is considered co-equal to the code itself, it is an excellent practice to use comments in the program source and notes in the API documentation to explain how the program works, why it is defined and implemented as it is, and how
to use it.

Similar Messages

  • Should I use a static method or an instance method?

    Just a simple function to look at a HashMap and tell how many non-null entries.
    This will be common code that will run on a multi-threaded weblogic app server and potentially serve many apps running at once.
    Does this have to be an instance method? Or is it perfectly fine to use a static method?
    public static int countNonNullEntries(HashMap hm){
    if(hm==null)return 0;
    int count=0;
    for(int i=0; i<hm.size(); i++) {
    if(hm.get(i)!=null)
    { count++;}
    return count;
    OR
    public int countNonNullEntries(HashMap hm){
    if(hm==null)return 0;
    int count=0;
    for(int i=0; i<hm.size(); i++) {
    if(hm.get(i)!=null)
    { count++;}
    return count;
    }

    TPD Opitz-Consulting com wrote:
    The question is the other way around: Is there a good reason to make the method static?
    Ususally the answer is: no.The question is: does this method need state? Yes -> method of a class with that state. No -> static.
    The good thing of having this method statig is that it meight decrese memory foot pring but unless you're facing memory related problem you should not think about that.I doubt there is any difference between the memory foot print of a static or not method.
    I'm not shure if this method beeing static maks problems in multithreaded environments like the one you're aiming at. But I do know that an immutable object is always thread save.Does the method use shared state (data)? No -> no multi threaded problems.
    Can the parameters be modified by different threads? Yes, if multiple threads modified the parameter map, but nothing you can do about it here (no way to force the calling thread to lock on whatever you lock on).
    So my answer to your question is: yes, it should be non static.The method should be static since it uses no state.
    It is thread-safe when only the calling thread can modify the passed map (using a synchronized or ConcurrentHashMap is not enough, since you don't call a single atomic method on the map).
    // Better use Map instead of HashMap
    // We don't care about the generic type, but that does not mean we should use a raw type
    public static int countNonNullEntries(Map<?, ?> map) {
      // whether to accept null map or not, no need for explicit exception
      // since next statement throw NPE anyway
      Collection<?> values = map.values();
      // note your method is called countNonNull, not countNull!
      // (original code it would need to by if(null != mapValue) notNullsCounter++;
      return values.size() - java.util.Collections.frequency(values, null);
    }

  • How to know that a method has been called and returning value of a method

    Hi, everyone! I have two questions. One is about making judgment about whether a method has been called or not; another one is about how to return "String value+newline character+String value" with a return statement.
    Here are the two original problems that I tried to solve.
    Write a class definition of a class named 'Value' with the following:
    a boolean instance variable named 'modified', initialized to false
    an integer instance variable named 'val'
    a constructor accepting a single paramter whose value is assigned to the instance variable 'val'
    a method 'getVal' that returns the current value of the instance variable 'val'
    a method 'setVal' that accepts a single parameter, assigns its value to 'val', and sets the 'modified' instance variable to true, and
    a boolean method, 'wasModified' that returns true if setVal was ever called.
    And I wrote my code this way:
    public class Value
    boolean modified=false;
    int val;
    public Value(int x)
    {val=x;}
      public int getVal()
      {return val;}
       public void setVal(int y)
        val = y;
        modified = true;
         public boolean wasModified()
          if(val==y&&modified==true)
          return true;
    }I tried to let the "wasModified" method know that the "setVal" has been called by writing:
    if(val==y&&modified==true)
    or
    if(x.setVal(y))
    I supposed that only when the "setVal" is called, the "modified" variable will be true(it's false by default) and val=y, don't either of this two conditions can prove that the method "setVal" has been called?
    I also have some questions about the feedback I got
    class Value is public, should be declared in a file named Value.java
    public class Value
    cannot find symbol
    symbol  : variable y
    location: class Value
    if(val==y&&modified==true)
    *^*
    *2 errors*
    I gave the class a name Value, doesn't that mean the class has been declared in a file named Value.java*?
    I have declared the variable y, why the compiler cann't find it? is it because y has been out of scale?
    The other problem is:
    Write a class named  Book containing:
    Two instance variables named  title and  author of type String.
    A constructor that accepts two String parameters. The value of the first is used to initialize the value of  title and the value of the second is used to initialize  author .
    A method named  toString that accepts no parameters.  toString returns a String consisting of the value of  title , followed by a newline character, followed by the value of  author .
    And this is my response:
    public class Book
    String title;
    String author;
      public Book(String x, String y)
       { title=x; author=y; }
       public String toString()
       {return title;
        return author;
    }I want to know that is it ok to have two return statements in a single method? Because when I add the return author; to the method toString, the compiler returns a complain which says it's an unreachable statement.
    Thank you very much!

    Lets take this slow and easy. First of all, you need to learn how to format your code for readability. Read and take to heart
    {color:0000ff}http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html{color}
    Now as to your first exercise, most of it is OK but not this:   public boolean wasModified()
          if (val == y && modified == true)
                return true;
    y being a parmeter to the setValue method exists only within the scope of that method. And why would you want to test that anyways? If modified evaluates to true, that's all you need to know that the value has been modified. So you could have   public boolean wasModified()
          if (modified == true)
                return true;
       }But even that is unnecessarily verbose, as the if condition evaluates to true, and the same is returned. So in the final analysis, all you need is   public boolean wasModified()
          return modified;
       }And a public class has to be declared in a file named for the class, yes.
    As for your second assignment, NO you cannot "return" two variables fom a method. return means just that: when the return statement is encountered, control returns to the calling routine. That's why the compiler is complaining that the statement following the (first) return statement is unreachable.
    Do you know how to string Strings together? (it's called concatenation.) And how to represent a newline in a String literal?
    db

  • Why there should not be many static methods.

    Why a java class should not have many static methods.How is memory managed in case of static methods.
    If a Utility class has static methods then we can use methods directly by class name but if we do not make the methods static then we can acess methods using object.How does it make the difference.I know that there remains a single copy of class variables/methods.But i want to know how class memory is managed and garbage collected.

    shobhit123 wrote:
    Why a java class should not have many static methods.How is memory managed in case of static methods.
    If a Utility class has static methods then we can use methods directly by class name but if we do not make the methods static then we can acess methods using object.How does it make the difference.I know that there remains a single copy of class variables/methods.But i want to know how class memory is managed and garbage collected.The reason to discourage static methods is stylistic rather than technical. It encourages object oriented thinking.
    Each loaded class is represented by a Class object, and associated with that it a block of memory for static fields. As with all such storage this block is, as viewed from code, rather like an array with one, or in the case of double or long values, two slots per field.
    Because the class loader maintains a map from FQN to Class this storage is only released if the class loader that loaded it becomes unreachable, which happens only in situations like the un-deployment of a web application or EJB.
    Local variables for static methods are allocated in a stack frame, just as with instance methods. There's really no significant difference there.

  • Why should I put another payment method and I cant choose none ?

    should i put another payment method to use my account?
    And i cant update my apps ..
    Whyyy i should put a valid payment method to use  my account ??
    And i don't have a master card anymore and i have apps that i  bought them and I want to download my apps without putting a new payment method 

    Well, you've got two choices: 1. Either associate a valid credit card with your account, or 2. Redeem an iTunes gift card.
    If you don't want to do either of the above, then you won't be able to use your account or update your apps.

  • Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the rows? Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the records?
    Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    The Oracle documentation has a good overview of the options available
    Generating XML Data from the Database
    Without knowing your version, I just picked 11.2, so you made need to look for that chapter in the documentation for your version to find applicable information.
    You can also find some information in XML DB FAQ

  • I have few PDf files on my computer and I want to add them to my ipod touch, please tell me the procedure on how should I do that? Secondly I want to run these Pdf files through the ibook app, as it also have the Pdf file sections

    I have few PDf files on my computer and I want to add them to my ipod touch, please tell me the procedure on how should I do that? Secondly I want to run these Pdf files through the ibook app, as it also have the Pdf file sections

    You should be able to just place them in your Books library in iTunes and check to ensure that your Book library is configured to sync to your iPod when you sync your iPod to iTunes.

  • I download my illustrator as Chinese edition, I want to change it back to English, how should I do that?

    I download my illustrator as Chinese edition, I want to change it back to English, how should I do that?
    My computer is MAC, do I need to download any extra things to fix it?

    Depends on the version:
    Adjust the install language | CCM

  • An automatic update arrived and installed itself but then told me it was incompatible with my version of Mac: 10.5.8. Firefox version 3.6.26 is on it now. It seems to work the same. Is there going to be a problem or should I ignore that message?

    An automatic update arrived and installed itself but then told me it was incompatible with my version of Mac: 10.5.8. Firefox version 3.6.26 is on it now. It seems to work the same. Is there going to be a problem or should I ignore that message?
    If I must replace it where do I get an older version?
    Thanks

    Firefox '''4 '''versions '''and later do not run on a PowerPC Mac''' and require at least OS X 10.5 and an '''Intel Mac'''.
    The latest''' supported''' version for your os is '''3.6.26''' , your are fully updated.
    see for more info:
    [http://www.mozilla.org/en-US/firefox/3.6/system-requirements/ Firefox 3.6 System Requirements]
    [http://www.mozilla.org/en-US/firefox/10.0/system-requirements/ Firefox 10 System Requirements]
    [For older Macs that aren't supported in Firefox 4+ versions, if you like, try TenFourFox for PowerPC's running Mac 10.4.11 & 10.5.8]
    http://www.floodgap.com/software/tenfourfox/
    http://tenfourfox.blogspot.com/
    https://code.google.com/p/tenfourfox/wiki/PluginsNoLongerSupported
    thank you
    Please mark "Solved" the answer that really solve the problem, to help others with a similar problem.

  • I want to clean all of the cookies and bugs that are in my computer causing it to be slow. What program should I use that is safe and won't mess up my computer?

    I want to clean all of the cookies and bugs that are in my computer causing it to be slow. What program should I use that is safe and won't mess up my computer?

    Problem description:
    I would like to clean up my computer. Its beginning to run slow and I believe cookies and bugs are apart of the reason.
    EtreCheck version: 2.0.6 (91)
    Report generated October 26, 2014 at 4:59:31 PM EDT
    Hardware Information: ℹ️
      MacBook Air (13-inch, Early 2014) (Verified)
      MacBook Air - model: MacBookAir6,2
      1 1.4 GHz Intel Core i5 CPU: 2-core
      4 GB RAM Not upgradeable
      BANK 0/DIMM0
      2 GB DDR3 1600 MHz ok
      BANK 1/DIMM0
      2 GB DDR3 1600 MHz ok
      Bluetooth: Good - Handoff/Airdrop2 supported
      Wireless:  en0: 802.11 a/b/g/n/ac
    Video Information: ℹ️
      Intel HD Graphics 5000 -
      Color LCD 1440 x 900
    System Software: ℹ️
      OS X 10.9.5 (13F34) - Uptime: 13 days 2:41:41
    Disk Information: ℹ️
      APPLE SSD SD0128F disk0 : (121.33 GB)
      S.M.A.R.T. Status: Verified
      EFI (disk0s1) <not mounted> : 210 MB
      Macintosh HD (disk0s2) /  [Startup]: 120.47 GB (70.38 GB free)
      Recovery HD (disk0s3) <not mounted>  [Recovery]: 650 MB
    USB Information: ℹ️
      Apple Internal Memory Card Reader
      Apple Inc. iPhone
      General USB Flash Disk 16.13 GB
      S.M.A.R.T. Status: Verified
      MSD (disk1s1) /Volumes/MSD : 16.13 GB (11.18 GB free)
      Apple Inc. BRCM20702 Hub
      Apple Inc. Bluetooth USB Host Controller
    Thunderbolt Information: ℹ️
      Apple Inc. thunderbolt_bus
    Gatekeeper: ℹ️
      Mac App Store and identified developers
    Kernel Extensions: ℹ️
      /Library/Extensions
      [loaded] foo.tap (1.0) Support
      [loaded] foo.tun (1.0) Support
    Startup Items: ℹ️
      tap: Path: /Library/StartupItems/tap
      tun: Path: /Library/StartupItems/tun
      Startup items are obsolete and will not work in future versions of OS X
    Problem System Launch Daemons: ℹ️
      [failed] com.apple.wdhelper.plist
    Launch Daemons: ℹ️
      [loaded] com.adobe.fpsaud.plist Support
      [running] com.perion.searchprotectd.plist Support
    User Launch Agents: ℹ️
      [loaded] com.genieo.completer.download.plist Support
      [loaded] com.genieo.completer.ltvbit.plist Support
      [running] com.genieo.completer.update.plist Support
      [loaded] com.google.keystone.agent.plist Support
      [invalid?] com.jdibackup.ZipCloud.autostart.plist Support
      [running] com.zeobit.MacKeeper.Helper.plist Support
    User Login Items: ℹ️
      iTunesHelper Application (/Applications/iTunes.app/Contents/MacOS/iTunesHelper.app)
    Internet Plug-ins: ℹ️
      DirectorShockwave: Version: 12.1.3r153 - SDK 10.6 Support
      Flash Player: Version: 15.0.0.189 - SDK 10.6 Support
      FlashPlayer-10.6: Version: 15.0.0.189 - SDK 10.6 Support
      JavaAppletPlugin: Version: 14.9.0 - SDK 10.7 Check version
      QuickTime Plugin: Version: 7.7.3
      Default Browser: Version: 537 - SDK 10.9
    User Internet Plug-ins: ℹ️
      TroviNPAPIPlugin: Version: 1.0 - SDK 10.9 Support
    Safari Extensions: ℹ️
      Trovi Search for Safari (Disabled)
    3rd Party Preference Panes: ℹ️
      Flash Player  Support
    Time Machine: ℹ️
      Time Machine not configured!
    Top Processes by CPU: ℹ️
          53% mds
          9% WindowServer
          3% mds_stores
          3% storeagent
          2% hidd
    Top Processes by Memory: ℹ️
      920 MB mds
      31 MB com.apple.WebKit.WebContent
      30 MB Messages
      29 MB Safari
      21 MB WindowServer
    Virtual Memory Information: ℹ️
      31 MB Free RAM
      713 MB Active RAM
      681 MB Inactive RAM
      1.09 GB Wired RAM
      17.85 GB Page-ins
      1.95 GB Page-outs

  • Last night, I saw my iPhone on the table in front of me and twice it made phone calls on its own.  I just watched it make the outgoing call as it sat in front of me.  Should I think that it has a virus? What should I do about it?

    Last night, I saw my iPhone on the table in front of me and twice it made phone calls on its own.  I just watched it make the outgoing call as it sat in front of me.  Should I think that it has a virus? What should I do about it?  
    Also, it's been a little quirky lately: slow to respond to key pad touching and making it impossible to delete Apps?
    Should I try wiping it and restoring it to factory settings?
    Thank you.
    Ben

    It isn't a virus.
    I would try the Restore from backup first and if that does not help try a Restore as a new iPhone.

  • How should i know that i have or already installed these in my database?

    my question regarding the steps in Post Installation Actions in installing patchset Oracle 9i Data Server 9.0.1 Patch Set 4 for Sun SPARC Solaris (32 bit Database)
    I'm not very sure about the instruction..
    How should i know that i have or already installed these in my database?
    Should i run all even if i don't know whether i use them or not?
    Or should i do nothing, and continue to my next patch installation?
    -Execute the following step only if you have JAVA enabled in your database:
    -Execute the following steps only if you have installed the Oracle Label
    Security option in the database you are attempting to modify:
    -Execute the following steps only if you have JAVA enabled in your database:
    -Execute the following steps only if you have installed UltraSearch in the
    database you are attempting to modify:
    -Execute the following steps only if you have installed Oracle Spatial or
    Oracle Locator in the database you are attempting to modify:
    -Execute the following steps only is you are using the RMAN catalog.:
    Plz advise..
    Regards,
    Rushdan Md Saad.

    It all depends. You don't NEED anything, Firefox runs just fine with it's default setup, and you don't need to install anything to fully experience the best of the web. But lets say you don't like ads. Install Adblock plus. Lets say you want to change themes, there are dozens of them. It's all personal preference.

  • After installing IOS6: after erasing the history of Safari, the next time I fire up Safari, I see a split-second of the last displayed screen of Safari. Not a big issue but it should not be that way.

    After installing IOS6:
    After erasing the history of Safari, the next time I fire up Safari, I see a split-second of the last displayed screen of Safari.
    Not a big issue but it should not be that way.

    Download a new copy of the Firefox program: http://www.mozilla.com/firefox/all.html
    Trash the current Firefox application to do a clean reinstall.
    Install the new version that you have downloaded.
    Your profile data is stored elsewhere in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder], so you won't lose your bookmarks and other personal data.

  • My iphone is switched off as low batery and still viberates. how should i handle that problem?my iphone is switched off as low batery and still viberates. how should i handle that problem?

    my Iphoe is switched off and still viberates. how should i handle that problem?

    Try to set it up as new device and don't use the backup afterwards:
    How to back up your data and set up as a new device

  • I just restored my iphone 4S. everything is backed up on the icloud. now it says i dont have a backup on icloud and the only other option i have is to set up as new iphone. should i do that? will it wipe out my icloud?

    i just restored my iphone 4S. everything is backed up on the icloud. i tried to restore from itunes but once its done syncing nothing happens. now it says i dont have a backup on icloud and the only other option i have is to set up as new iphone. should i do that? will it wipe out my icloud?

    when i go to icloud.com all my contacts still exist, notes, etc. is my iphone gonna recognize my contacts if i set it up as a new phone?

Maybe you are looking for

  • Calling Recursive function with Powershell to list all documents in the document library under a SIte collection

     function Recurse($RootFolder,$List) {                         $Context.Load($RootFolder)                         $Context.Load($RootFolder.Folders)                         $Context.ExecuteQuery()                         foreach($folder in $RootFolde

  • Cost/Price diffrences posting (PRD)

    Dear ALL, I am facing the issue in (PRD)Cost price diffrence account postings. In Article Master (Retail) using Moving avg price while doing GR price diffrence posting to PRD account due to negative stock indicator in Article master. Ex : In Article

  • PL/SQL Function: Adding Days to Date

    I have a function that adds a given number of days to a date, and excludes Saturday, Sunday, or Monday if needed with parameters. The problem is when the given date is a Friday, you need to add one day, and you exclude Saturday and Sunday i.e. DAYSBE

  • FI and SD integration

    Hello, We are doing SD invoice but we don't want to send any data into COPA what should we do but we need to turn the COPA on as we are sending the data from FI.The reason for this is we do very few invoices  in SD and we don't want to capture those

  • Reverse value order horizontal axis keynote chart

    Hi I am trying to create a chart that shows rankings (so a lower number is better), so I want the low number to show the highest column. So I guess the zero should be at the top of the Y axis. Does anyone know how to invert the values on Y to show ze