inheritance

C# Cannot convert from IEnumerable<Base> to IEnumerable<Derived>

I recently run into trouble when trying to AddRange(IEnumerable) to a List. Probably a classic issue, but I do not really get it yet. I understand that methods expecting a List parameter are not satisfied with a List, because they might try to add a Base to the List, which is obviously impossible. But if i get this correctly, since IEn...

Entity Framework: How can I enable a one table per class inheritance with a rowversion field?

Why can't I define a member with the same name in subclasses? I have a one table per class inheritance with a rowversion timestamp field in each table. It seems like the Entity designer should allow for this and use the new keyword on the property to make it happen. What is the workaround? How can I specify the same field in an inher...

Django form - set label

I have a form that inherits from 2 other forms. In my form, I want to change the label of a field that was defined in one of the parent forms. Does anyone know how this can be done? I'm trying to do it in my __init__, but it throws an error saying that "'RegistrationFormTOS' object has no attribute 'email'". Does anyone know how I can ...

Java: Creating a subclass object from a parent object

Newbie Java question. Say I have: public class Car{ ... } public class Truck extends Car{ ... } Suppose I already have a Car object, how do I create a new Truck object from this Car object, so that all the values of the Car object is copied into my new Truck object? Ideally I could do something like this: Car c = new Car(); /* ....

How (if at all) can you make an ASP.NET UserControl inherit from another UserControl?

In Windows Forms it's easy to inherit one user control from another. The inherited control contains all the controls of the parent form, and you can add some more. Can the same be done with ASP.NET? I'm talking about the .ASCX type of user controls. ...

CSS Control Inheritance - Inheriting Other Control Styles

Two parts to my question: 1) Is there a way to inherit another control's attributes and styles in CSS? Assume the controls have no parent/child hierarchy and can be completely different control types: IE: #MyFirstControl { width: 100px; } #MySecondControl { width: MyFirstControl.styles.width; /* This doesn't work */ } 2) Assume...

Any way to allow classes implementing IEntity and downcast to have operator == comparisons?

Basically here's the issue. All entities in my system are identified by their type and their id. new Customer() { Id = 1} == new Customer() {Id = 1}; new Customer() { Id = 1} != new Customer() {Id = 2}; new Customer() { Id = 1} != new Product() {Id = 1}; Pretty standard scenario. Since all Entities have an Id I define an interface fo...

Common Columns in ADO.NET Entities

Is there a way to extract common columns from various tables into a single base class in the ADO.NET Entity Framework when using the EDMX designer? For instance, every single table in my database has a "LastUpdatedBy" and "LastUpdatedDate" column that is necessary for auditing purposes. I would like to set these values automatically in...

Abstract Inheritance and Generics (with playing cards)

So, I've been working on some playing cards in Java. (Not for any practical purpose really, I just enjoy playing cards and they're good practice) Now, right now, I'm making some Card Structures, decks, hands, piles, etc. They're all essentially the same, so I figure that I'd like to use some inheritance. The problem that I've encount...

Delphi: properties with same name in descending class

In one file, I have a baseclass with a ID-property: type TBase = class(TObject) private FID: integer; public property ID: integer read FID write SetID; end; In a second file, I have another class, descending from TBase. By accident, or ignorance or what ever, a new property/field with the same name as an exsi...

Ruby - Getting Array of non-ancestral methods in class

Hello. I want to create a class that has one method that calls all other methods that are not in the super class. Is there a way I can use obj.methods to only get the non-ancestral methods? Or is there another way to do it entirely. Thank you ...

How do I prevent JAXB from binding superclass methods of the @XmlRootElement when marshalling?

I have a class that is annotated as the @XmlRootElement with @XmlAccessorType(XmlAccessType.NONE). The problem that I am having is that the superclass's methods are being bound, when I do not want them to be bound, and cannot update the class. I am hoping there is an annotation that I can put on the root element class to prevent this f...

Howto design for extension

There is a Checkstyle rule DesignForExtension. It says: if you have a public/protected method which is not abstract nor final nor empty it is not "designed for extension". Read the description for this rule on the Checkstyle page for the rationale. Imagine this case. I have an abstract class which defines some fields and a validate meth...

What's the advantage of this indirect function call?

I found the following code in a library: class Bar { public: bool foo(int i) { return foo_(i); } private: virtual bool foo_(int i) = 0; }; Now I'm wondering: Why would you use this indirection? Could there be any reasons why the above would be better than the simple alternative: class Bar { public: virtual bool foo(int i) ...

Generics, Inheritance and the new operator

Here is something that I find myself using from time to time and I just wanted to get some feedback on the merits of the practice. Lets say that I have a base class: abstract class RealBase { protected RealBase(object arg) { Arg = arg; } public object Arg { get; private set; } public abstract void DoThatThingY...

Need to override method that is in a namspace with another class which constructs it

Hello, I am trying to override a method on a control in the Community Server SDK called 'InlineTagsContainerTagEditor'. When I find the source for this control, it is inside of a file with another class called 'TaggableContentTagEditableList'. Here is what I think the relevant parts are: namespace CommunityServer.Controls { publi...

c# inheriting generic collection and serialization...

Hi, The setup: class Item { private int _value; public Item() { _value = 0; } public int Value { get { return _value; } set { _value = value; } } } class ItemCollection : Collection<Item> { private string _name; public ItemCollection() { _name = string.Empty; } public string ...

Fluent Nhibernate and pluggable inheritance

Is there any way to define/expand inheritence without changing base table mapping with fluent nhibernate? For example with Castle.ActiveRecord (based on nhibernate) you can define inheritance like this: [ActiveRecord("entity"), JoinedBase] public class Entity : ActiveRecordBase { [PrimaryKey] public int Id{get;set;} } [ActiveR...

Trying to override formatting implementation of static method in compiled SDK

Hello, I am working with the Community Server framework. One of the provided form controls allows the user to update his/her 'status'. For example: 'Joe: is going to get coffee : 12:30am'. I want to change the format of that message before it goes into the database(goes in as formatted HTML). I want to take out the ":" character betw...

Can I change properties of inherited controls at design time?

I am using visual inheritance and was wondering if there is a way to change the properties of inherited controls at design time, preferably in the form designer. If not, then in the designer code. I have my control declared as Public in the base class. I can access it in the child form code, but not in the form designer. Is this just no...