Ask coding questions

← Back to all posts
How to perfect object oriented programming?
superpeter (2)

Basically, just submit tips on how to make OOP as efficient and easy as possible!

-Either python, ruby, or pseudo-code is acceptable if you need to add code to your answer.

-It's not a competition, but feel free to correct someone if they say something blatantly wrong.

21natzil (1141)

Here are a few tips.

  1. Avoid global variables. The only times you'd ever use global variables are for static numbers and string and what not.
  2. DRY (Don't repeat yourself)
  3. While you can, and should when you must, it's generally better if you don't let other objects set another object's attributes. Only read from them.
  4. If your dictionary keys are different types, it should probably be a class.
  5. This one applies to just python. Don't use private values! They're not even that private, just used protected values. If you don't know what that means, I suggest you look it up.