polymorphism

ASP.NET: Shadowing Issues

情到浓时终转凉″ 提交于 2019-12-13 03:41:05
问题 I have two classes in two separate libraries (one VB, one C#): Public Class Item ... Public Overridable ReadOnly Property TotalPrice() As String Get Return FormatCurrency(Price + SelectedOptionsTotal()) End Get End Property End Class and public class DerivedItem : Item { ... public new Decimal TotalPrice { get { return Price + OptionsPrice; } } } As you can see, the DerivedItem.TotalPrice shadows the Item.TotalPrice property. However, when trying to retrieve the DerivedItem.TotalPrice value,

how to write a function to process two types of input data in golang

走远了吗. 提交于 2019-12-13 03:26:07
问题 I have multiple struct s share some fields. For example, type A struct { Color string Mass float // ... other properties } type B struct { Color string Mass float // ... other properties } I also have a function that only deals with the shared fields, say func f(x){ x.Color x.Mass } How to deal with such situations? I know we can turn the color and mass into functions, then we can use interface and pass that interface to the function f . But what if the types of A and B cannot be changed. Do

Would this be a good case for polymorphism

江枫思渺然 提交于 2019-12-13 02:50:57
问题 Sorry if this is a really basic question but I struggling with how I should attack this. I am trying to wrap up some commands for a OLE object, the basic spec looks like this: Set Window window_id //Units is part of the position setter. [ Position ( x, y ) [ Units paper_units ] ] [ Width win_width [ Units paper_units ] ] [ Height win_height [ Units paper_units ] ] ..... this goes on for about 20+ commands, all optional. Where anyhting in between [] is optional. So I need to create a class

Inheritance mucking up polymorphism in C++?

£可爱£侵袭症+ 提交于 2019-12-13 02:49:10
问题 Perhaps my knowledge of inheritance and polymorphism isn't what I thought it was. Can anyone shed some light? Setup (trivialization of problem): class X { }; class Y { }; class Base { public: void f( X* ) {} }; class Child: public Base { public: void f( Y* ) {} }; Question: This should work, right? int main( void ) { X* x = new X(); Y* y = new Y(); Child* c = new Child(); c->f( x ); c->f( y ); return 0; } I get errors (GCC 4.4) to the tune of: `no matching function for call to 'Child::f(X*&)'

accessing interface's overridden variable

廉价感情. 提交于 2019-12-13 02:25:27
问题 Lets say I have an interface with a field - String type = "interface". It's implementing class has a field - String type = "class". Is there any way to access the interface's field through that class anymore? 回答1: Yep.. because basically interface variable are public static final or in other word, a constant.. you can access it in a static way using your IYourInterfaceName.type 回答2: public interface Firstone { String type="interface"; } public class Abc implements Firstone { /** * @param args

Call private method from the world in c++

雨燕双飞 提交于 2019-12-13 01:26:22
问题 I realy don't understand why it works, but below code shows an example of calling private method from the world without any friend classes: class A { public: virtual void someMethod(){ std::cout << "A::someMethod"; } }; class B : public A { private: virtual void someMethod(){ std::cout << "B::someMethod"; } }; int main(){ A* a = new B; a->someMethod(); } outputs: B::someMethod Doesn't it violates encapsulation rules in C++? For me this is insane. The inheritance is public, but the access

Can't access object in the array java

旧街凉风 提交于 2019-12-13 01:26:14
问题 else if (control.equals("Car") == true) { owner = (scanner.nextLine()); address = (scanner.nextLine()); phone = (scanner.nextLine()); email =(scanner.nextLine()); convertible= (scanner.nextBoolean()); color = (scanner.nextLine()); vehicleLot[i] = new car(owner, address, phone, email, convertible, color); System.out.println(vehicleLot[i].getOwner()); System.out.println(vehicleLot[i].getAddress()); //System.out.println(vehicleLot[i].getColor()); } The above code is in my main method. The line

Derived class object override a function of base class in a vector of objects

百般思念 提交于 2019-12-13 00:12:49
问题 so I'm having an issue of calling the override function of a derived class when it's stored in an array of it's base class. The base class is called Obstacle, and the derived class is Cliff. Obstacle has a virtual function called drawToBackground, and Cliff, which inherits from Obstacle also has a function called drawToBackground, both of which are void. I then have a vector of Obstacles, called obstsVec. In this vector, I store a bunch of Obstacles and a Cliff. Now say that the cliff is the

Default arguments in function and polymorphism [closed]

☆樱花仙子☆ 提交于 2019-12-12 23:32:19
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Why can default arguments in C++ functions be considered polymorphism? Why is it consider ad-hoc polymorphism and universal

how to check the Class Type(instanceof) in java template method?

☆樱花仙子☆ 提交于 2019-12-12 23:30:31
问题 public class Test { private static Object createInstance(String classPath) { try { Class<?> tClass = Class.forName(classPath); if (tClass != null) { return tClass.newInstance(); } } catch (Exception e) { e.printStackTrace(); } return null; } @SuppressWarnings("unchecked") public final static <INPUT, OUTPUT> Filter<INPUT, OUTPUT> getFilter(String path) { return (Filter<INPUT, OUTPUT>) createInstance(path); } public final static <INPUT, OUTPUT> OUTPUT filter(String path, INPUT mes) { Filter