If two classes both need to know about each other to do their job, i.e. class A must maintain a reference to class B and class B must maintain a reference to class A, is this generally a sign that inheritance would be a better idea than composition, provided you aren't violating the Liskov Substitution principle? My thinking is that thi...
This may seem kind of "homework-ish" and/or trivial, but it is for a real business purpose; it's just the easiest way I could think of to explain what I'm conceptually trying to do.
Suppose I have an Animal class, and some other classes (Bird, Cat, Kangaroo). Each of these inherits from Animal.
Animal might look like this:
public cl...
I have a class I am serializing with C#'s XmlSerializer. It is marked with the XmlRoot attribute, and I would like to inherit this attribute in a derived class.
Looking at the documentation it does not say that XmlRoot sets Inherit to false with AttributeUsageAttribute (Inherit is supposed to default to true), but I get an error when tr...
The ruby class-instance stuff is giving me a headache. I understand given this...
class Foo
@var = 'bar'
end
...that @var is a variable on the created class's instance.
But how do I create a sub-class overridable class variable?
Here is an example of what I would do in Python:
class Fish:
var = 'fish'
def v(self):
return sel...
I'm using pseudo-interfaces in C++, that is, pure abstract classes. Suppose I have three interfaces, IFoo, IBar and IQuux. I also have a class Fred that implements all three of them:
interface IFoo
{
void foo (void);
}
interface IBar
{
void bar (void);
}
interface IQuux
{
void quux (void);
}
class Fred : implements ...
I'm using an API that has a "Member" class. I wish to extend this so i have create "MemberProfile" which inherits from "Member"
I have some issue creating the constructor for this class. I wish to something like the following
var member = Member.GetCurrentMember();
var memberProfile = new MemberProfile(member);
How would the...
There's lots of articles and posts explaining how JavaScript inheritance works, but I'm curious why JavaScript was implemented using prototypal inheritance instead of classical inheritance. I love JavaScript so I'm not saying it's bad thing... I'm just curious.
...
Hello guys!
I will try to summarize my question.
I have a base class "Base" with three properties. Four classes inherit from it - "A", "B", "C" and "D". They add their own additional properties. I have mapped this with InheritanceType.JOINED. Now I want to search for "Base" entities, which means that I search on the common properties ...
class X
{
protected:
void protectedFunction() { cout << "i am protected" ; }
};
class Y : public X
{
public:
using X::protectedFunction;
};
int main()
{
Y y1;
y1.protectedFunction();
}
This way i am able to expose one of the function of base class. Doesnt this violate the encapsulation principle
is there a specific r...
Something I've wondered for a long time: why aren't Delphi records able to have inheritance (and thus all other important OOP features)?
This would essentially make records the stack-allocated version of classes, just like C++ classes, and would render "objects" (note: not instances) obsolete. I don't see anything problematic with it. T...
I have a Base Class with two constructors, requiring a parameter:
public abstract class StoreBase
{
private readonly SomeObject_sobj;
protected StoreBase(SomeObject sobj)
{
_sobj = sobj;
}
protected StoreBase(OtherObject oobj)
{
_sobj = new SomeObject(oobj);
}
}
Then I have a derived clas...
Consider the Employee, Manager, and Assistant classes:
public class Emp
{
public string Name { get; set; }
public Manager Manager { get; set; }
public Assistant Assistant { get; set; }
}
public class Manager : Emp
{
}
public class Assistant : Emp
{
}
The goal is to DISALLOW a piece of code to access a property like this...
Hello,
I am calling a function several times as I am testing several responses. I am asking on how I call a function earlier in the program, changing a variable in this function and then calling it. Below is a snippet of the code.
class AbsoluteMove(unittest.TestCase):
def Ssh(self):
p=pexpect.spawn('ssh [email protected]...
Hi,
I have one header file which uses a virtual function.
This is declared and defined:
#ifndef HeaderH
#define HeaderH
class Base {
<some code>
public:virtual int checkVal(int& val) { return val;}
};
#endif
I have another header file which declares some functions, and inherits from this base header.
Finally, I have the impleme...
I am using LINQ to SQL
and want to add functions to autogenerated EntitySet< TEntity > collections.
eg.
City.Houses
where Houses is automatically generated EntitySet < House >
I am using extension method to add extract function to the EntitySet < House > class
so that I can get something like
City.House.FindByID(id);
but now I ...
eg.
House.CityID
House.City
I can make the City property "override" as its an association.
Can I do the same to House.CityID make it "override"
...
I have a class hierarchy in PHP 5.2.9.
The base class has a protected property which is an associative array.
The child classes can add some elements to the array.
The child classes are declared in the separate files (plugins), which will be created and added by multiple developers.
Which is the best way to add the elements to the pr...
I inherit from a root form that has a next and back button in, then use these buttons on some subforms and get the buttons called twice, i beleive the problem to be outlined in the MSDN here:
http://msdn.microsoft.com/en-us/library/e33683a5(VS.71).aspx
how would i apply the advice they give to C# rather than VB?
It is causing lots ...
Suppose I have some extension methods but also need to extend the object's state. Seeing as there is no support for extension properties in C#, would using shared static Dictionary be a good solution?
For example something like this:
class Foo
{
// 3rd party class
}
static class Helper
{
private static Dictionary<Foo, Gui...
I have a base class called Packet:
// Header File
class Packet {
public:
virtual bool isAwesome() const {
return false;
}
}
and an inherited class called AwesomePacket:
// Header File
class AwesomePacket : public Packet {
public:
virtual bool isAwesome() const {
return true;
}
}
However, when I insta...