I am working with python at the moment and wonder about something. I'm not too good with object programming, as I've always coded with imperative languages (C mostly).
So I'm asking myself.
Say I have an instance of class_1 called c1, declared this way:
c1 = class_1(bla bla bla...)
Say c1 has a heck lot of variable declarations inside, like
self.x = ...
self.y = ...
self.z = ...
#etc etc
Now, I have an instance of type class_2, called c2. Say c2 is declared INSIDE c1's init() function, like that
c2 = class_2(bla bla bla...)
Now, I wonder how I could... acces the objects of c1 from within c2?
Some could say I could make class_2 inherit from class_1. That's not exactly what I want in fact. The reason is that, class_1 should include in a logical way objects that are of type class_2, but class_2 needs to access variables from class_1! If I would make class_2 inherit from class_1, I would always have to... declare class_2 objects in the external (to the classes) code. I want to work, in the external code, with class_1 objects. How can I reasonably do that? Starting to be a nightmare...
Thanks!
EDITED:
The context in which I use it... I have, as an assignment, to write a small space video game. I have to calculate trajectories in space. I also have a map. Some parameters such as acceleration, rotation speed, etc... Are specific to the 'map' : i.e. we design a map with obstacles and all, but depending on the map, the some physics constant vary. I also have a 'physcis' class to handle different calculations related to the trajectory, position upating, etc etc. So I just want to be able to use the many many many instances of different objects which are contained in the 'map' class, so that I can use these variables inside the physics class! Is it legit? Thanks!
selffrom the__init__as an argument toclass_2. Also, your terminology seems a bit off. Ifclass_1is your class,c1is not a class, it is an instance.c1andc2look like instances here, not classes.class_1isBinaryTree,class_2isNode, and BinaryTrees contain Nodes) or an is-a relationship (for example,class_1isAnimal,class_2isDog, and you want to decide whether to return aCat,Dog, orDancingWalruswithout requiring the call site to explicitly call theDogconstructor).