java - What is the rationale for using per-method/field access specification? -


in c++ access specifier field or method based on location under first declared access specification:

public:   int my_public_variable; private:   void secretprivateoperations();   int internal_counter; 

what design rationale behind java specifying access prepending access specifier each method/field?

public int my_public_variable; private void secretprivateoperations(); private int internal_counter; 

compare:

public:     t a();     t b();     ...     t z(); 

versus

public:     t a() {         <lots of code>     }     t b() {         <lots of code>     } protected:     t c() {         <more code>     } public:     t d() {         <more code>     } 

if "factor out" access specifiers this, things can pretty nasty pretty quickly. yes, indentation helps. yes, have ctrl-f. there still can lot of noise through (multi-thousand line files, example), , having take mind off of task kind of thing wouldn't productivity.

java , c++ java deal in different ways. java keeps access specifiers local, knowing method you're working on enough determine scope. c++ stuffs declarations access specifier can "factored out". may not nice when implementing methods, it's more concise in header files, , possibly easier grok too.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -