oop

If I've cast a subclass as its superclass, and call a method that was overridden in the subclass, does it perform the overridden or original method?

做~自己de王妃 提交于 2021-01-27 07:10:52
问题 Consider: Dog is a subclass of Animal , and Dog overrides Animal.eat() Animal[] animals = getAllAnimals(); for (int i = 0; i < animals.length; i++) { animals[i].eat(); } If Animal.eat() is overriden by Dog.eat() , which one is called when the method is called from an identifier of type Animal ( animals[i] ?) 回答1: The subclass method will be called. That's the beauty of polymorphism. 回答2: The subclass will be the only method call, unless the subclass calls the superclass like this: class Dog {

Repository, Service or Domain object - where does logic belong?

Deadly 提交于 2021-01-27 03:55:57
问题 Take this simple, contrived example: UserRepository.GetAllUsers(); UserRepository.GetUserById(); Inevitably, I will have more complex "queries", such as: //returns users where active=true, deleted=false, and confirmed = true GetActiveUsers(); I'm having trouble determining where the responsibility of the repository ends. GetActiveUsers() represents a simple "query". Does it belong in the repository ? How about something that involves a bit of logic, such as: //activate the user, set the

Repository, Service or Domain object - where does logic belong?

喜欢而已 提交于 2021-01-27 03:55:20
问题 Take this simple, contrived example: UserRepository.GetAllUsers(); UserRepository.GetUserById(); Inevitably, I will have more complex "queries", such as: //returns users where active=true, deleted=false, and confirmed = true GetActiveUsers(); I'm having trouble determining where the responsibility of the repository ends. GetActiveUsers() represents a simple "query". Does it belong in the repository ? How about something that involves a bit of logic, such as: //activate the user, set the

Repository, Service or Domain object - where does logic belong?

久未见 提交于 2021-01-27 03:53:56
问题 Take this simple, contrived example: UserRepository.GetAllUsers(); UserRepository.GetUserById(); Inevitably, I will have more complex "queries", such as: //returns users where active=true, deleted=false, and confirmed = true GetActiveUsers(); I'm having trouble determining where the responsibility of the repository ends. GetActiveUsers() represents a simple "query". Does it belong in the repository ? How about something that involves a bit of logic, such as: //activate the user, set the

Creating a dynamic class instance programmatically in PHP with variable arguments?

佐手、 提交于 2021-01-27 02:57:25
问题 I've some code that creates ad instance with a dynamic class (i.e. from a variable): $instance = new $myClass(); Since the constructor has different argument count depending on $myClass value, How do I pass a variable list of arguments to the new statement? Is it possible? 回答1: class Horse { public function __construct( $a, $b, $c ) { echo $a; echo $b; echo $c; } } $myClass = "Horse"; $refl = new ReflectionClass($myClass); $instance = $refl->newInstanceArgs( array( "first", "second", "third"

Creating a dynamic class instance programmatically in PHP with variable arguments?

我怕爱的太早我们不能终老 提交于 2021-01-27 02:57:10
问题 I've some code that creates ad instance with a dynamic class (i.e. from a variable): $instance = new $myClass(); Since the constructor has different argument count depending on $myClass value, How do I pass a variable list of arguments to the new statement? Is it possible? 回答1: class Horse { public function __construct( $a, $b, $c ) { echo $a; echo $b; echo $c; } } $myClass = "Horse"; $refl = new ReflectionClass($myClass); $instance = $refl->newInstanceArgs( array( "first", "second", "third"

What is the difference between `super(…)` and `return super(…)`?

折月煮酒 提交于 2021-01-26 20:13:00
问题 I'm just now learning about python OOP. In some framework's source code, i came across return super(... and wondered if there was a difference between the two. class a(object): def foo(self): print 'a' class b(object): def foo(self): print 'b' class A(a): def foo(self): super(A, self).foo() class B(b): def foo(self): return super(B, self).foo() >>> aie = A(); bee = B() >>> aie.foo(); bee.foo() a b Looks the same to me. I know that OOP can get pretty complicated if you let it, but i don't have

What is the difference between `super(…)` and `return super(…)`?

萝らか妹 提交于 2021-01-26 20:11:38
问题 I'm just now learning about python OOP. In some framework's source code, i came across return super(... and wondered if there was a difference between the two. class a(object): def foo(self): print 'a' class b(object): def foo(self): print 'b' class A(a): def foo(self): super(A, self).foo() class B(b): def foo(self): return super(B, self).foo() >>> aie = A(); bee = B() >>> aie.foo(); bee.foo() a b Looks the same to me. I know that OOP can get pretty complicated if you let it, but i don't have

What is the difference between `super(…)` and `return super(…)`?

梦想与她 提交于 2021-01-26 20:09:45
问题 I'm just now learning about python OOP. In some framework's source code, i came across return super(... and wondered if there was a difference between the two. class a(object): def foo(self): print 'a' class b(object): def foo(self): print 'b' class A(a): def foo(self): super(A, self).foo() class B(b): def foo(self): return super(B, self).foo() >>> aie = A(); bee = B() >>> aie.foo(); bee.foo() a b Looks the same to me. I know that OOP can get pretty complicated if you let it, but i don't have

What is the difference between `super(…)` and `return super(…)`?

我是研究僧i 提交于 2021-01-26 20:07:35
问题 I'm just now learning about python OOP. In some framework's source code, i came across return super(... and wondered if there was a difference between the two. class a(object): def foo(self): print 'a' class b(object): def foo(self): print 'b' class A(a): def foo(self): super(A, self).foo() class B(b): def foo(self): return super(B, self).foo() >>> aie = A(); bee = B() >>> aie.foo(); bee.foo() a b Looks the same to me. I know that OOP can get pretty complicated if you let it, but i don't have