<reponame>ThiagoPiovesan/OOP-Python<filename>04 - Class vs Static Methods/helper.py<gh_stars>0
#--------------------------------------------------------------------#
# Help program.
# Created by: Jim - https://www.youtube.com/watch?v=XCgWYx-lGl8
# Changed by: <NAME>
#--------------------------------------------------------------------#

# When to use class methods and when to use static methods ?
#--------------------------------------------------------------------#
class Item:
    @staticmethod
    def is_integer():
        '''
        This should do something that has a relationship
        with the class, but not something that must be unique
        per instance!
        '''
    @classmethod
    def instantiate_from_something(cls):
        '''
        This should also do something that has a relationship
        with the class, but usually, those are used to
        manipulate different structures of data to instantiate
        objects, like we have done with CSV.
        '''

# THE ONLY DIFFERENCE BETWEEN THOSE:
# Static methods are not passing the object reference as the first argument in the background!

#--------------------------------------------------------------------#
# NOTE: However, those could be also called from instances.

item1 = Item()
item1.is_integer()
item1.instantiate_from_something()
#--------------------------------------------------------------------#
- Class vs Static Methods/helper.py<gh_stars>0
#--------------------------------------------------------------------#
# Help program.
# Created by: Jim - https://www.youtube.com/watch?v=XCgWYx-lGl8
# Changed by: <NAME>
#--------------------------------------------------------------------#

# When to use class methods and when to use static methods ?
#--------------------------------------------------------------------#
class Item:
    @staticmethod
    def is_integer():
        '''
        This should do something that has a relationship
        with the class, but not something that must be unique
        per instance!
        '''
    @classmethod
    def instantiate_from_something(cls):
        '''
        This should also do something that has a relationship
        with the class, but usually, those are used to
        manipulate different structures of data to instantiate
        objects, like we have done with CSV.
        '''

# THE ONLY DIFFERENCE BETWEEN THOSE:
# Static methods are not passing the object reference as the first argument in the background!

#--------------------------------------------------------------------#
# NOTE: However, those could be also called from instances.

item1 = Item()
item1.is_integer()
item1.instantiate_from_something()
#--------------------------------------------------------------------#
#--------------------------------------------------------------------# # Help program. # Created by: Jim - https://www.youtube.com/watch?v=XCgWYx-lGl8 # Changed by: <NAME> #--------------------------------------------------------------------# # When to use class methods and when to use static methods ? #--------------------------------------------------------------------# This should do something that has a relationship         with the class, but not something that must be unique         per instance! This should also do something that has a relationship         with the class, but usually, those are used to         manipulate different structures of data to instantiate         objects, like we have done with CSV. # THE ONLY DIFFERENCE BETWEEN THOSE: # Static methods are not passing the object reference as the first argument in the background! #--------------------------------------------------------------------# # NOTE: However, those could be also called from instances. #--------------------------------------------------------------------#