python - OOP - organising big classes -


i starting write big python library area of mathematics.

so have data structure (defined in class a) represents mathematical model.

i have bunch of smaller functions, have put in a:

a.f(), a.g(),...

which more or less "helper functions" needed calculate more important functions a.x(), a.y(),... end user interested in.

all of these functions of course depend on data in a.

but number of methods in growing , growing , getting confusing. how 1 split such class smaller pieces. lets say, data structure basic operations in , "methods" calculations on structure?

what usual approach , pythonic approach?

you can use pure functional approach , move methods class users not supposed call on object instance separate files.

in pure functional approach functions don't depend on internal state, have no side effects , calculate return value based on arguments provided.

an example illustration replacing following:

# shape.py class shape:      def __init__(self, x, y):         self.x = x         self.y = y      def area(self):         return self.x * self.y 

with:

# shape.py class shape:      def __init__(self, x, y):         self.x = x         self.y = y  # func.py def area(shape):     return shape.x * shape.y 

of course, might not idea extract area method of shape class separate function in file, can move "helper functions" separate files , call them class methods.

this simplify helper function testing.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -