• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Class method vs instance method

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody,
i have a stupid question maybe, when i should write class method and when i should write instance method, because i have written a big project and the both are running. Can you give a clear example to that(in the case class and instance method) ? and what is the disadvantage if i use for all my method only class method. Any help will be appreciated, thanks
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Arifin,

As for myself, I would write class methods:
  • For global processes that may affect all instances of the class (for example, setting class defaults)
  • For utilities relevant to what the class deals with (for example utility methods in Math class)


  • Otherwise, I would write instance methods. (Obviously, once you need to use a non static member of the class, you need to write an instance method)

    Hope that helps,
    reply
      Bookmark Topic Watch Topic
    • New Topic