annotations to naming patterns

Posted on 2011-04-26
Last Modified: 2012-05-11
Prefer annotations to naming patterns

I was reading above staemtent. I have not understood the statement, concept behind clearly.
Please advise. Any ideas, sugestions, sample code, links, resources highly appreciated. thanks in advance
Question by:gudii9
    1 Comment
    LVL 26

    Accepted Solution

    The idea here is that it's better to use a language feature (annotations) then a convention (how you name things) in order to make your code correct.

    For example you could decide whenever you derive one class from another to name each method so it starts with "over" to indicate that it may have been overridden.  You methods would be:

    class A {
       public String overGetName() { return "my name is A" ; }
       private void getNumber() { return 6 ; } // Not named over since can't be overridden

    class B extends A {
        public String overGetName() { return "my name is B" ; }

    The better approach is to use an annotation.  In this case the language has one - @Override so you'd instead write:

    class A {
       public String getName() { return "my name is A" ; }
       private void getNumber() { return 6 ; } // Not named over since can't be overridden

    class B extends A {
        @Override     <-- This annotation indicates we're overriding the method
        public String getName() { return "my name is B" ; }

    Since it looks like you're just learning the language I'm not going to explain how to build an annotation - that's fairly complex stuff.  But this should help explain why they're better to use than just naming things carefully.


    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now