Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.

Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


Member Since 06 Oct 2012
Offline Last Active Nov 28 2012 09:50 PM

Topics I've Started

"Getters" and "Setters" - do you write them if you don't need them?

07 October 2012 - 08:28 PM

Hello all!

I've been lurking these forums for a while and finally decided to join up and be a real member of the community. I figured I'd introduce myself by asking everyone a simple question. When writing in an object oriented language, do you write a "getter" and "setter" method for every attribute of an object? What if you never intend to change the value of said attribute?

As an example: I'm working on my first game, a clone of pong. my class Ball has an attribute named size. Obviously the size of the ball in a game of pong never changes, but it felt strange to not write a setSize() method. Now I have code in my program that will never be used - and that feels a little strange too.

I know that there is no right or wrong answer to this question, I'm just interested in your individual opinions. Take it easy,