[Solved] Why the method in some class I created, ask me for input “self”? [closed]

[ad_1] You have to create an object of your class: class MyClass: def __init__(self,a=1,b=2): self.a=a self.b=b def function1(self): self.c=self.a/self.b + 5 return(self.c) print(MyClass().function1()) MyClass() creates an object that can be used to access attributes in the class. For a general instance: m = MyClass() print(m.function1()) 6 [ad_2] solved Why the method in some class I … Read more

[Solved] Which OO Design is better and why? [closed]

[ad_1] In my point of view I think that you can go more further in term of Single Responsibility Principle(RSP). But I’m not really sure if it relevant to make an interface for Editor. class Image{ string path } Image image = new Image(); interface Rotatory { rotate(image); } class RightRotator implements Rotatory{ rotate(image){ /*Your … Read more

[Solved] Getting a none type error python 3?

[ad_1] In insertEnd, you’re guaranteeing you always have None for actualnode at the end of the loop: def insertEnd(self, data): self.size += 1 newnode = Node(data) actualnode = self.head # Keep going until actualnode is None while actualnode is not None: actualnode = actualnode.nextnode # Here actualnode will always be None actualnode.nextnode = newnode To … Read more

[Solved] Violating Single Responsibility Principle and static methods [closed]

[ad_1] A few random thoughts. (a) Can you even pin down precisely what it means for a class to have some “responsibility” ??? And subsequently, if (as I suspect) all you have is vague notions without any formally observable / measurable properties / characteristics to pin down the meaning of “responsibility”, then how can you … Read more

[Solved] This confuses in javascript [duplicate]

[ad_1] The value of this changes depending upon how the function was invoked; Collection.prototype.onOpen(); // `this` refers to `Collection.prototype` // vs var c = new Collection(); c.onOpen(); // `this` refers to `c` // vs var o = {}; Collection.prototype.onOpen.call(o); // `this` refers to `o` // vs var foo = Collection.prototype.onOpen; foo(); // `this` could be … Read more

[Solved] Doing Age Calculations via OOP [closed]

[ad_1] You can use the DateTime class to easily manipulate dates. I have put the $dateFormat outside of the method because you could also use that to validate your input in setBirthDate if you saw fit. protected $dateFormat=”m/d/Y”; public function getAge() { // Create a DateTime object from the expected format return DateTime::createFromFormat($this->dateFormat, $this->birthDate) // … Read more

[Solved] Null error is coming in javascript

[ad_1] Well this is one broken part (unless it’s intentional?) Set the ID property to null this.ID= null; Try to access the property you just set equal to null this.matchName= this.ID.substr(this.ID.lastIndexOf(‘_’)); This code is running in the initialization (constructor) of your Check class and will error out. Here’s what I think you want, with better … Read more