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

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 solved Why the method in some class I created, ask … Read more

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

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 implementation*/ … Read more

[Solved] Getting a none type error python 3?

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 fix … Read more

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

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 say … Read more

[Solved] This confuses in javascript [duplicate]

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 `window` … Read more

[Solved] Doing Age Calculations via OOP [closed]

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) // Compare … Read more

[Solved] Null error is coming in javascript

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 formatting … Read more