oop

Is a constructor __init__ necessary for a class in Python?

时光怂恿深爱的人放手 提交于 2021-01-21 08:28:28
问题 I read that the constructor is like the first argument passed to the class, which makes sense to me since the parameters seem to be passed to the class via the __init__ method. For example, class NewsStory(object): def __init__(self, guid, title, subject, summary, link): self.guid = guid self.title = title self.subject = subject self.summary = summary self.link = link def get_guid(self): return self.guid def get_title(self): return self.title def get_subject(self): return self.subject def get

Why and when use polymorphism?

孤人 提交于 2021-01-21 07:44:43
问题 I'm new to OOP and polymorphism has given me a hard time: class Animal { public virtual void eat() { Console.Write("Animal eating"); } } class Dog : Animal { public override void eat() { Console.Write("Dog eating"); } } class Program { public void Main() { Animal dog = new Dog(); Animal generic = new Animal(); dog.eat(); generic.eat(); } } So that prints Dog eating Animal eating But why not to just use the Dog type instead of animal, like Dog dog = new Dog()? I assume this comes handy when

Why and when use polymorphism?

本秂侑毒 提交于 2021-01-21 07:43:00
问题 I'm new to OOP and polymorphism has given me a hard time: class Animal { public virtual void eat() { Console.Write("Animal eating"); } } class Dog : Animal { public override void eat() { Console.Write("Dog eating"); } } class Program { public void Main() { Animal dog = new Dog(); Animal generic = new Animal(); dog.eat(); generic.eat(); } } So that prints Dog eating Animal eating But why not to just use the Dog type instead of animal, like Dog dog = new Dog()? I assume this comes handy when

Is class an object in object oriented language

天涯浪子 提交于 2021-01-21 07:06:58
问题 Is class an object in object oriented language? How are Class methods accessed by just name of the class.method name ? (internal working). Is this same as a object.method ? And If the Class is same as object (belong to object class which is super class of every thing in OO) and we instantiate it (make object of it), can we make instance of an instance of an class other than Object class. (Mainly interested in the theoretical perspective even if practically not required ever) 回答1: Well, it

Very long class names

早过忘川 提交于 2021-01-21 06:17:09
问题 I try to name a class (also members, properties and so forth) as exact as I can. But sometimes I’m not sure if this is so clever if the class name becomes huge (50 chars and more). The handling is so what uncomfortable and the code becomes difficult to read. The question occured for me seldom and therefore I don’t have much experience with working with such long names but from time to time (now) it occurs. How other people handle this? Have you an approximate upper limit and then make

Very long class names

非 Y 不嫁゛ 提交于 2021-01-21 06:17:01
问题 I try to name a class (also members, properties and so forth) as exact as I can. But sometimes I’m not sure if this is so clever if the class name becomes huge (50 chars and more). The handling is so what uncomfortable and the code becomes difficult to read. The question occured for me seldom and therefore I don’t have much experience with working with such long names but from time to time (now) it occurs. How other people handle this? Have you an approximate upper limit and then make

PHP - passing variables to classes

我怕爱的太早我们不能终老 提交于 2021-01-20 20:01:11
问题 I trying to learn OOP and I've made this class class boo{ function boo(&another_class, $some_normal_variable){ $some_normal_variable = $another_class->do_something(); } function do_stuff(){ // how can I access '$another_class' and '$some_normal_variable' here? return $another_class->get($some_normal_variable); } } and I call this somewhere inside the another_class class like $bla = new boo($bla, $foo); echo $bla->do_stuff(); But I don't know how to access $bla, $foo inside the do_stuff

PHP - passing variables to classes

两盒软妹~` 提交于 2021-01-20 19:58:08
问题 I trying to learn OOP and I've made this class class boo{ function boo(&another_class, $some_normal_variable){ $some_normal_variable = $another_class->do_something(); } function do_stuff(){ // how can I access '$another_class' and '$some_normal_variable' here? return $another_class->get($some_normal_variable); } } and I call this somewhere inside the another_class class like $bla = new boo($bla, $foo); echo $bla->do_stuff(); But I don't know how to access $bla, $foo inside the do_stuff

PHP - passing variables to classes

这一生的挚爱 提交于 2021-01-20 19:57:50
问题 I trying to learn OOP and I've made this class class boo{ function boo(&another_class, $some_normal_variable){ $some_normal_variable = $another_class->do_something(); } function do_stuff(){ // how can I access '$another_class' and '$some_normal_variable' here? return $another_class->get($some_normal_variable); } } and I call this somewhere inside the another_class class like $bla = new boo($bla, $foo); echo $bla->do_stuff(); But I don't know how to access $bla, $foo inside the do_stuff

Can one abstract class extend another abstract class and increase functionality

扶醉桌前 提交于 2021-01-20 15:11:52
问题 I have an abstract class. I want to extend the abstract class by another abstract class and then implement the extended abstract class. Is it possible .If yes, whether it's a good approach in point of view regarding OOPS? 回答1: I'm not sure about Java in particular, but it should be valid. In terms of OOP, if it makes sense, then run with it. To use some old examples, you might have a Vehicle abstract class and then LandVehicle and FlyingVehicle abstract classes. As long as your example makes