inheritance

Multiple Interface Inheritence without using Interfaces

Yes, the title doesn't make much sense, but here's my situation. I have two interfaces, say IGen and ITrans. Some of my classes implement IGen, some implement ITrans and some implement both ITrans has one method (Translate) and IGen has one method (Generate). For the classes that implement both ITrans and IGen Generate simply calls Tra...

F# Operator Resolution

Hi, I have a class called Vector which implements a number of operators such as + and properties such as Count. Vector is also subtyped by classes such as DenseVector, SparseVector which inherit from Vector. Now in F# when I write the following let foo (v : #Vector) (w : #Vector) = v + w let bar (v : #Vector) (w : #Vector) = v.Count + ...

Looking for some OOAD advice for Reporting

I have the need to create an arbitrary amount of reports in many different file formats. Most of the formats I am able to use Smarty to template the output. However, outputting to Excel and PDF complicate things and require the use of FPDF or TCPDF and PHPExcel. I am trying to figure out the best way to organize my classes via one or ...

How to clear inherited customErrors elements in Web.config?

As the article ASP.NET Configuration File Hierarchy and Inheritance says the Web.config file for a specific Web site contains settings that apply to the Web site and inherit downward through all of the ASP.NET applications and subdirectories of the site. I have these settings for a "parent" application <customErrors mod...

Overridden function pointer problem at template base class C++

hi, I implemented a template base class for observer pattern, template<class T> class ActionListener { public: ActionListener(void); virtual ~ActionListener(void); void registerListener(T* listener); void unregisterListener(T* listener); template<typename Signal> void emit(Signal signal); templa...

Call base method in Javascript using Douglas Crockford's functional inheritance

Basically how do I call a base method using this patter below? var GS = {}; GS.baseClass = function (somedata) { var that = {}; that.data = somedata; //Base class method that.someMethod = function(somedata) { alert(somedata); }; return that; }; GS.derivedClass = function(somedata) { var that = GS.baseClass(somedata);...

ASP.NET Session Inheritence

I have two classes that my pages and controls inherit from. These two classes get the same basic set of information, but as it stands the code is implemented twice. Is there a way to inherit from one base class? public partial class SessionPage : System.Web.UI.Page { protected override void OnInit(EventArgs e) { // Loads the session...

Generics, Inheritance, and Casting

My question has to do with casting classes inside a generic type. While I realize that casting objects like List<string> to List<object> requires support for covariance to prevent adding object objects to a list that contains strings, I am wondering why a cast like below is not accepted by the compiler and whether it is solvable employin...

Coding classes with the same behaviour + unique behaviour

I have a set of classes which have similarities and differences. They derive from an interface, which defines the unique behaviour amongst these different classes, and a base class to call the common functionality in the several classes. Is there a design pattern which governs how these sort of classes are created? Is it acceptable to u...

Why is implicit conversion allowed from superclass to subclass?

Can someone tell me why the line with "//Compiles" compiles, and why the line with "//Doesn't Compile" does not? I don't understand why A would be implicitly convertible to B, not the other way round. public class SomeClass { static public void Test() { AClass a = new AClass(); BClass b = new BClass(); a = b; // Compiles b...

How to approach a class which implements an interface and has a base class?

Imagine the following code: MyService myService = new MyService(); myService.Start(); myService.DoStuff(); The MyService class looks like this: public class MyService : ClientBase, IMyService { ... } Now I wanted to change the existing code to call this class by using its interface: IMyService myService = GetMyService(); myService...

Getting rid of error C2243

Is it possible to getting rid of error C2243? class B {}; class D : protected B {}; D d; B *p = &d; // conversion from 'D *' to 'B &' exists, but is inaccessible I had this error in my app and at the end I've managed to compile it by making an explicit conversion: D d; B *p = (B*)&d; I can't understand why by making class D inhe...

How to subclass a templated base class?

I have the following data structures: struct fastEngine { ... } struct slowEngine { ... } template<typename T> class Car { T engine; vector<T> backupEngines; virtual void drive() = 0; } class FastCar : public Car<fastEngine> { virtual void drive() { // use the values of "engine" in some way } } class SlowCar : p...

c# inherit how to override the type of a member in abstract class in child class

I have following code: public abstract class TestProperty { public abstract Object PropertyValue { get; set; } } public class StringProperty: TestProperty { public override string PropertyValue {get;set} } which generate compilation error, I wonder should I have to use generic type in TestProperty in order to achive my goal o...

Isolating Ruby methods from overriding in subclasses? (like Java's private methods)

In Ruby, I'd like to acheive something like this Java sample: class A { private void f() { System.out.println("Hello world"); } public void g() { f(); } } class B extends A { public void f() { throw new RuntimeException("bad guy");} } public class Try { public static void main(String[] args) { new B().g();} } ...

Why is System.Windows.Shape.Path sealed?

I was trying to extend the shape class to contain an additional variable but have found the class is sealed. How can I achive this simply, using an alternate implementation approach? Is creating a new class and storing a shape an passing all the method calls through the easiest approach; I'm sure there is a better way though? ...

How can I factor out the code duplication here?

So, I'd like to hear what you all think about this. I have a project where three different inheritance paths need to all implement another base class. This would be multiple inheritance and isn't allowed in C#. I am curious how I can implement this without code duplication. EDIT: I don't own the three classes. The three classes are f...

Java Program Error

Please can anyone tell me what is the error in the following piece of code? Question is Create a class person which has A variable ‘name’ which stores the name of the person. A constructor that takes a single argument that is used to initialize the name variable A method getName() which displays the name. A protected method setName()...

C++ override/overload problem

I'm facing a problem in C++ : #include <iostream> class A { protected: void some_func(const unsigned int& param1) { std::cout << "A::some_func(" << param1 << ")" << std::endl; } public: virtual ~A() {} virtual void some_func(const unsigned int& param1, const char*) { some_func(param1); } }; class B : public A { p...

Does an API based on inheritance violate OCP? Can this be solved with a provider model/dependency injection?

I'm designing an API for the first time, and trying to follow SOLID guidelines. One of the things I find myself struggling with is balancing OCP and testability with simplicity and ease of extensibility. This open-source API is geared toward scientific modeling and computation. The aim is that various groups will be able to easily impor...