Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6101957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:33:33+00:00 2026-05-23T13:33:33+00:00

I think the concept is called overloading. Right now I’m writing a class that

  • 0

I think the concept is called overloading.
Right now I’m writing a class that will provide getter and setter methods, and am stuck on a design issue.

Both methods are one-liners that simply set a value, or return a value.

def set_number(self, num):

   self.count = num

def get_number(self):

   return self.count

Would it be better to save space and make the class “look” smaller by doing something that will basically combine the two methods into one and then just decide which line should be executed depending on whether the num argument is provided?

Or should I just stick to clarity and keep them separated? Some people feel that it’s a “waste of space” to keep all these one-liners on their own, while others disagree and prefer splitting them up.

Any reasons why I would choose one or the other?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:33:33+00:00Added an answer on May 23, 2026 at 1:33 pm

    In Python, you should prefer not to use getters and setters at all. Instead simply reference the count attribute directly, e.g. print instance.count or instance.count = 5

    The point of getters and setters in other languages is for encapsulation and for future-proofing in case you need to add logic to the getters or setters. In Python you can accomplish this by later using property, which will not break your existing API.

    @property
    def number(self):
         # do extra logic if necessary
        return self.count
    

    Properties can also have setters – see: http://docs.python.org/library/functions.html#property

    Python is not Java. =)

    Extra bonus reading material:

    • http://tomayko.com/writings/getters-setters-fuxors
    • http://eli.thegreenplace.net/2009/02/06/getters-and-setters-in-python/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've developed some concept code for a project that I will be working on
I think I understand the concept of virtual methods and vtables, but I don't
What do you think about the concept of using ORO instead of traditional Garbage
I think the file that is produced is an .asm file, any idea how
I think most people know how to do this via the GUI (right click
I've got a custom class (which resembles an NSArray in concept and, hopefully, formatted
Windows-7 introduced a concept of virtual folder, called 'Libraries'. I am working on implementing
OSGi applications are composed of modules called bundles. The problem is that any reasonably
I'm writing a small assembly routine called isOdd, which, as the name implies, returns
I think one of the more difficult concepts to understand in the Zend Framework

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.