I am working on a simple problem to represent a few types that have a hierarchical structure. There is a data row that contains some data, and the data could vary from type type of row to another. A simple row might only have a title and date, while an extended row may contain a title, description, date and an image. I am not new to Java...
I understand the basics of inheritance but this one is confusing me. How would you go about saying:
An album object has one or more artist objects
An album object has one or more song objects
My current code only will only allow one song per object:
class Song extends Album{}
class Album extends Artist{}
I'm sure i'm overlooking s...
=== CLARIFICATION ====
The 'answers' older than March are not answers to the question in this post!
Hello
In my domain I need to track allocations of time spent on Activities by resources. There are two general types of Activities of interest - ones base on a Project and ones based on an Account.
The notion of Project and Account hav...
What's the best way to initialize constants or other fields in inherited classes? I realize there are many syntax errors in this example, but this is the best example to explain clearly what I am trying to do.
public abstract class Animal {
public abstract const string Name; // #1
public abstract const bool CanFly;
public abstract...
I have a C# interface defined as so:
public interface IMenuSecurityService
{
void SetSecurityFlags(List<MenuItem> items);
}
I need to implement this interface in a VB.Net class. When I implement the SetSecurityFlags method with the items parameter passed ByVal, it compiles.
Public Sub SetSecurityFlags(ByVal items As List(Of L1.C...
(C#, VS2008) In a program I'm working on, I've got lots of objects that all have an ID and implement IComparable so that List<>-s of the various objects are easily searchable by ID. Since I hate copy/pasting code, I thought I'd abstract that bit of functionality down to a base class, like so:
using System;
namespace MyProg.Logic
{
...
i have 3 classes: class PassengerDetails which is inherited by class FlightDetails which in turn is inherited by class Details. Both, PassengerDetails and FlightDetails have a method Accept which accepts some parameters and assigns it to local variables (declared as protected) of that class. What i need to do is by using a method Show in...
Fixed issues with the code.
Ok, I think I need to clarify the question.
new A.example(); outputs "A"
What should be inside the example method so that it could output "???"?
Is that even possible?
public class Letter {
public virtual void AsAString() {
Console.WriteLine("???");
}
public void example() {
t...
I have class X, an abstract class, and classes A and B that inherit from it. Classes A and B each have their own 'return_something' function. I have another method elsewhere that calls 'return_something' on a series of objects, all of type X. 'return_something' returns something different depending on whether it is an A or a B, so I c...
Hi there.
I have a plugin module that extends the AR with a before_save callback to log all changes made into a relating acts_as_commentable comment. This works fine.
However, I want to add more details to the comment such as who made the change etc. I have made a couple of fields available to the model instance log_message and log_ow...
Is there a way to "inherit" imports?
Example:
Common enum:
public enum Constant{ ONE, TWO, THREE }
Base class using this enum:
public class Base {
protected void register(Constant c, String t) {
...
}
}
Sub class needing an import to use the enum constants convenient (without enum name):
import static Constant.*; /...
Hi,
I am using PHP 5.3 stable release and sometimes I encounter very inconsistent behaviours. As far as I know in inheritance all attributes and methods(private, public and protected) in super class are passed child class.
class Foo
{
private $_name = "foo";
}
class Bar extends Foo
{
public function getName()
{
retur...
Basically, I have a pure virtual class Base, and a concrete class Derived which inherits from Base. I then allocate a piece of memory and treat it as an array of Derived via a simple cast. Then, I populate the array using =. Finally, I loop through the array, trying to call the virtual method GetIndex that is declared in Base and defined...
Hi -
We currently have several WCF services that expose our domain model directly across the wire. In other words, we don't have a layer of DTOs to map between our domain and service layers. I have no choice but to directly decorate our domain objects with [DataContract] and [DataMember]. I want to implement IExtensibleDataObject on ...
I have defined an "Action" pure abstract class like this:
class Action {
public:
virtual void execute () = 0;
virtual void revert () = 0;
virtual ~Action () = 0;
};
And represented each command the user can execute with a class.
For actual undo/redo I would like to do something like this:
Undo
Action a = historyStack.p...
Ok, I think I did my due diligence here. I couldn't find any reference on how to use a parent form element in a subclassed form. May be because it's obvious to everyone but me. It's got me stumped. This is what I tried.
At first, within my form constructor I called
parent::__construct($options = null);
then accessed the parent elemen...
I just found that I am confused about one basic question in C++
class Base {
};
class Derived : public Base {
}
Base *ptr = new Derived();
What does it mean? ptr is pointing to a Base class or Derived class? At this line, how many memory is allocated for ptr? based on the size of Derived or Base?
What's the difference between th...
As you can see in the code below, I have an Abstract Base Class "HostWindow", and class that derives from it "Chrome". All the functions are implemented in Chrome. The issue is, I can't call functions in Chrome if they're virtual.
class HostWindow : public Noncopyable {
public:
virtual ~HostWindow() { }
// Pure virtual function...
This is kind of complicated so please bear with me.
The Setup
most of our code base is in VB.net. I'm developing a project in c# that uses a lot of the assemblies from the VB.net code.
There are three relevant classes in VB.net
Public MustInherit Class mdTable
Public Sub New(ByVal sqlConnectionStr As String, Optional ByVal maxSec...
I develop CHDataStructures, a library of Cocoa data structures to supplement those in Foundation. It includes a fair number of classes (stacks, queues, and dequeues) that share common implementation details, so it makes sense to design them with a common parent class which I treat as abstract (Objective-C doesn't natively enforce this co...