oop

What is use of Parent object instantiating with child class

99封情书 提交于 2021-02-06 09:23:49
问题 Please tell me what is of parent object instantiating with child class like: public class A { public A() { Console.WriteLine("A"); } public virtual void method() { Console.WriteLine("AM"); } } public class B : A { public B() { Console.WriteLine("B"); } public new void method() { Console.WriteLine("BM"); } public void method1() { Console.WriteLine("BM1"); } } class Program { static void Main(string[] args) { A obj = new B();// what is use of it? obj.method(); Console.Read(); } private void

Observer pattern or Callback?

限于喜欢 提交于 2021-02-05 20:20:14
问题 I have to do a design of a DownloadManager , but my main question is related to the notifications that a Download can send to the DownloadManager like onUpdate() to update a progress bar, onError() , onFinish() , etc. Somehow the DownloadManager has to receive this notifications from its Download s. I've thought 2 possible ways: Observer pattern Callbacks Observer pattern Basically there are 1 Observable and N Observers. In my case the DownloadManager has te be an Observer and the Downloads

Observer pattern or Callback?

对着背影说爱祢 提交于 2021-02-05 20:11:22
问题 I have to do a design of a DownloadManager , but my main question is related to the notifications that a Download can send to the DownloadManager like onUpdate() to update a progress bar, onError() , onFinish() , etc. Somehow the DownloadManager has to receive this notifications from its Download s. I've thought 2 possible ways: Observer pattern Callbacks Observer pattern Basically there are 1 Observable and N Observers. In my case the DownloadManager has te be an Observer and the Downloads

python/pygame, pass input from a class to another class

只愿长相守 提交于 2021-02-05 09:33:08
问题 there is a way to pass a value or a variable from a class to another class without having to pass through the main function I'm using python 回答1: well, of course you can access other objects attributes in methods of a specific object. e.g: class A(object): def method(self, other): other.somevar = 5 class B(object): pass def main(): a = A() b = B() b.somevar = "Hello World" a.method(b) print(b.somevar) # now prints '5' 来源: https://stackoverflow.com/questions/7610531/python-pygame-pass-input

python/pygame, pass input from a class to another class

你。 提交于 2021-02-05 09:31:02
问题 there is a way to pass a value or a variable from a class to another class without having to pass through the main function I'm using python 回答1: well, of course you can access other objects attributes in methods of a specific object. e.g: class A(object): def method(self, other): other.somevar = 5 class B(object): pass def main(): a = A() b = B() b.somevar = "Hello World" a.method(b) print(b.somevar) # now prints '5' 来源: https://stackoverflow.com/questions/7610531/python-pygame-pass-input

Why do we need an Object parameter for equals method? [duplicate]

佐手、 提交于 2021-02-05 09:20:08
问题 This question already has answers here : java why should equals method input parameter be Object (6 answers) Overloading in Java and multiple dispatch (6 answers) Closed 2 years ago . I was making some tests with the java equals method and I figured out that if my parameter is not of the generic type Object the test won’t pass, even if the two objects I create are of that type. Let’s say I want to check if an object is an animal, what I tried to do is writing down: public boolean equals

Can I define a property within an object prototype (method)?

℡╲_俬逩灬. 提交于 2021-02-05 09:10:28
问题 Question part 1: I've made an object constructor with properties in it, but I am wondering if I could define another property of the object within one of it's methods. For example: var Player = function(p1) { this.property1 = p1; this.property2 = 0; } then, can I define this.property3 in a method, like: Player.prototype.drawMethod = funtion() { this.property3 = 1; } and have it accessible, like: var obj = new Player(true); if (obj.property3 ===1 && obj.property1 === 1) { //code } else { obj

Is ArrayList<X> an aggregation or composition?

邮差的信 提交于 2021-02-05 08:35:06
问题 I am preparing for my programming exam and came across this question, I know that in aggregation the object is borrowed, and in composition the object is owned. Is the answer composition? Is an ArrayList<X> an aggregation of X or composition of X ? ArrayList<Point> pts = new ArrayList<Point>(); Point p = new Point(0., 0., 0.); pts.add(p); p.setX( 10.0 ); System.out.println(p); System.out.println(pts.get(0)); 回答1: From here: Simple rules: A "owns" B = Composition : B has no meaning or purpose

Is ArrayList<X> an aggregation or composition?

▼魔方 西西 提交于 2021-02-05 08:33:06
问题 I am preparing for my programming exam and came across this question, I know that in aggregation the object is borrowed, and in composition the object is owned. Is the answer composition? Is an ArrayList<X> an aggregation of X or composition of X ? ArrayList<Point> pts = new ArrayList<Point>(); Point p = new Point(0., 0., 0.); pts.add(p); p.setX( 10.0 ); System.out.println(p); System.out.println(pts.get(0)); 回答1: From here: Simple rules: A "owns" B = Composition : B has no meaning or purpose

What does it mean when a parent class has a super()?

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-05 08:26:11
问题 As far as i know, super() is used to call the methods overwritten in the subclass (like an overwritten __init__ in the subclass). Also, i know that all python classes inherit from a special class called object . While studying OOP i ran into a weird example: class A(object): def __init__(self): print('A.__init__') super().__init__() class B(object): def __init__(self): print('B.__init__') super().__init__() class C(A, B): def __init__(self): print('C.__init__') super().__init__() I understand