Python Forum
too many methods in class - redesign idea?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
too many methods in class - redesign idea?
#1
I have one xml file (famtree.xml) that I read in, that holds many parameters about family tree data. It has many levels, root level is me, then parents, grandparents....

Now I am currently creating one class instance of that data: class myFamTree

Then I used to create (too many) class methods to return some data. get_own_parents(), get_parents_mom(), get_parents_dad(), get_parents_parents_mom(), get_parents_parents_dad(), etc.....

I feel this is getting too many methods. Is there any good practice how to clean code such scenario and avoid a superclass like here?
Reply
#2
show your code so we can help
Gribouillis likes this post
Reply
#3
i can't - it's protected
Reply
#4
Then paraphrase. Post enough to provide insight into the issues you are having.

I suspect your data has too little structure, you are ignoring the structure it has.

I would expect a family tree to be a tree of people. In addition to information like birth date and place, a People has 2 parents, X siblings and Y children. To find your grandparents you ask for your parents, and then ask for their parents. To find your uncles you ask for your parents, ask for their siblings, and filter out those that are not male. To find first cousins you get your parents, get their siblings, get their children.

To do these kinds of queries you need very few methods. Mostly you need a way to take the result of a query, filter it, and us it in another query. This is the kind of thing that relational databases are really good at. If you put your family tree data into a database you might get all the functionality you need for free. Almost no programming required.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Class test : good way to split methods into several files paul18fr 4 468 Jan-30-2024, 11:46 AM
Last Post: Pedroski55
  Structuring a large class: privite vs public methods 6hearts 3 1,047 May-05-2023, 10:06 AM
Last Post: Gribouillis
  access share attributed among several class methods drSlump 0 1,056 Nov-18-2021, 03:02 PM
Last Post: drSlump
  a function common to methods of a class Skaperen 7 2,566 Oct-04-2021, 07:07 PM
Last Post: Skaperen
  Listing All Methods Of Associated With A Class JoeDainton123 3 2,332 May-10-2021, 01:46 AM
Last Post: deanhystad
  Special Methods in Class Nikhil 3 2,263 Mar-04-2021, 06:25 PM
Last Post: Nikhil
  cant able to make methods interact with each other in the class jagasrik 2 1,785 Sep-16-2020, 06:52 PM
Last Post: deanhystad
  Question about naming variables in class methods sShadowSerpent 1 1,999 Mar-25-2020, 04:51 PM
Last Post: ndc85430
  a class calling one of its own methods? Skaperen 1 1,829 Jul-21-2019, 04:43 AM
Last Post: Gribouillis
  Do objects get their own copy of the class methods? Charles1 1 2,083 Feb-02-2019, 04:40 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020