Python Forum
[Solved] Novice question to OOP: can a method of class A access attributes of class B
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] Novice question to OOP: can a method of class A access attributes of class B
#2
It is not a good idea to have a class reference attributes of an unrelated (not a superclass) class. It is almost acceptable if class B is responsible for creating creating instances of class A. "I brought you into this world and I can can check your credit card balance." It is still bad parenting, but sometimes required. If there are A objects outside the scope of B, and B does things other than cater to A, it is a better design to have a helper function that knows about A and B and implements the passage of information between them.

As to the PyQt example, I would either bind the control's signal to a method in A, or have the control call a helper function that knows about A.
BigMan likes this post
Reply


Messages In This Thread
RE: Novice question to OOP: can a method of class A access attributes of class B - by deanhystad - Mar-14-2022, 11:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How does this code create a class? Pedroski55 6 475 Apr-21-2024, 06:15 AM
Last Post: Gribouillis
  class definition and problem with a method HerrAyas 2 289 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  Printing out incidence values for Class Object SquderDragon 3 319 Apr-01-2024, 07:52 AM
Last Post: SquderDragon
  class and runtime akbarza 4 420 Mar-16-2024, 01:32 PM
Last Post: deanhystad
  Operation result class SirDonkey 6 582 Feb-25-2024, 10:53 AM
Last Post: Gribouillis
  The function of double underscore back and front in a class function name? Pedroski55 9 736 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  super() and order of running method in class inheritance akbarza 7 816 Feb-04-2024, 09:35 AM
Last Post: Gribouillis
  Class test : good way to split methods into several files paul18fr 4 510 Jan-30-2024, 11:46 AM
Last Post: Pedroski55
  Good class design - with a Snake game as an example bear 1 1,858 Jan-24-2024, 08:36 AM
Last Post: annakenna
  question about __repr__ in a class akbarza 4 640 Jan-12-2024, 11:22 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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