Changes between Version 4 and Version 5 of CODE_TASKS_REQUIREMENTS


Ignore:
Timestamp:
09/16/08 18:00:19 (17 years ago)
Author:
Tanya
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CODE_TASKS_REQUIREMENTS

    v4 v5  
    158158 
    159159Always rethrow the exception if You dont have information how to handle it. 
    160 Since PropertyVetoException is checked exception, it may be good to wrap it in a RuntimeException. 
     160Since !PropertyVetoException is checked exception, it may be good to wrap it in a !RuntimeException. 
    161161Consult other people and think of exception handling policy. 
    162162 
     
    173173        } 
    174174}}} 
     175 
     176= Global variables = 
     177 
     178Do NOT use global variables as a way to pass arguments between non-public methods. 
     179This is an unclear method, potentially very dangerous - a lot of mistakes can be done using it. 
     180 
     181= Use final = 
     182Usage of final modifier for classes, methods,and especially class members and method variables is a very good practise and prevents from a number of mistakes. 
     183 
     184== classes == 
     185When writing a class, one of the things we have to think of is - 'is our class designed in a way that it can be inherited?' 
     186In 90% of the cases the answer of this question is 'NO'. However if we don't make it final, some people may decide to inherit it and this will cause a lot of problems. 
     187There are some very famous examples of such mistakes being made: 
     188java.sql.Date inherits java.util.Date and it causes a lot of problems - You can read about them here: 
     189[http://www.thunderguy.com/semicolon/2003/08/14/java-sql-date-is-not-a-real-date/] 
     190The problem all starts from the fact that in the documentation of java.util.Date it is written that the class should not be inherited,but it was not declared final. 
     191Always put final modifier for your classes if they are not designed to be inherited. 
     192 
     193== class methods == 
     194Sometimes we design our classes for inheritance but there are some public methods that are critical and we do not want the inheritant to override them - again put final modifier. 
     195 
     196== class variables == 
     197When we have a class member that is initialized in the constructor and should never be changed through all the instance life - ALWAYS put final modifier. 
     198This will prevent someone change the refference of that class member, that would have lead to wrong behaviour. 
     199 
     200In !FrameView class, we have !PageView parent, that was has to be final but it is not. 
     201{{{ 
     202private PageView parent; 
     203}}} 
     204Replaced with: 
     205{{{ 
     206private final PageView parent; 
     207}}} 
     208== method variables == 
     209The same as class members. 
     210{{{ 
     211        public void saveAs() { 
     212                File file = selectSaveFile(); 
     213                if(file != null){ 
     214                        this.book.saveTo(file); 
     215                } 
     216        } 
     217}}} 
     218file shall be declared private.