I am learning about object oriented programming from
Problem solving with Algorithms and Data structures book.
I have trouble understanding the setNextPin(self,source) method in Connector Class. I understand that the tgate.setNextPin(self) mean tgate.setNextPin(tgate,self) but what really is self here ?? It is confusing with me what the self of Connector stand for ?? Logically, this method will set tgate.PinA = self, and becaause we want tgate to take value from fgate so self == fgate ? Sorry if the question is stupid or confusing
class Connector:
def __init__(self, fgate, tgate):
self.fromgate = fgate
self.togate = tgate
tgate.setNextPin(self)
def getFrom(self):
return self.fromgate
def getTo(self):
return self.togate
I think I understand the basic idea of self, but if we have:
g1 = AndGate("G1")
g2 = AndGate("G2")
g3 = OrGate("G3")
c1 = Connector(g1,g3)
So in this case which is g3.setNexPin(self) will set the next pin of g3 to c1 ?? but c1 is only a connector and donot hold any value ??