Hi
How can I prevent inheritance of some methods or properties in derived classes?!
public class BaseClass : Collection
{
//Some operations...
//Should not let derived classes inherit 'Add' method.
}
public class DerivedClass : BaseClass
{
public void DoSomething(int Item)
{
...
I found those two terms in the book of Meyers, but what is the difference, thanks in advance for any help
...
I'm a pretty seasoned programmer but I'm just now diving into C++ and it's... well... more difficult than PHP and Python. I keep having unresolved external errors when trying to create an object from some classes. It's broken up into multiple headers and files but here is a basic idea from one of my classes:
die.h:
#ifndef DIE_H
#defin...
In C#, currently i'm doing the following code to filter out a specific set of classes that inherit from the CaptureType that is passed to the method.
public static CaptureType[] ListPluginsWith<CaptureType>()
{
List<CaptureType> plugins = new List<CaptureType>();
foreach (var plugin in Bot.AutoPlugins)
{
...
I don't understand the following phenomenon, could someone explain me please what I got wrong?
public class BaseClass
{
public BaseClass()
{
BaseClass.Instance = this;
}
public static BaseClass Instance
{
get;
private set;
}
}
public class SubClassA : BaseClass
{
public SubClassA()
...
I really didn't know how to specify the problem in the title, so here's the gist of it.
I am writing graph classes Graph, Node, and Edge, and then subclassing them into VisGraph, VisNode and VisEdge to obtain a drawable graph (in C++). I then need to further subclass those into specific classes that depend on certain data. So I have a l...
First time poster, long time reader, so bear with me:
Python decorators are fun to use, but I appear to have hit a wall due to the way arguments are passed to decorators. Here I have a decorator defined as part of a base class (the decorator will access class members hence it will require the self parameter).
class SubSystem(object):
...
Why did the Python designers decide that subclasses' __init__() methods don't automatically call the __init__() methods of their superclasses, as in some other languages? Is the Pythonic and recommended idiom really like the following?
def Superclass(object):
def __init__(self):
print 'Do something'
def Subclass(Superclass)...
Hi,
How can I add in my custom class an option to a field existing in the parent model?
More concretely: I'm writing a custom comment model inheriting from django.contrib.comments.models.Comment.
I'd like to add the option editable = False to the IPAddressField.
thank you
...
Hi, can I mix inheritance and templates this way ? :
template <class T>
class AbstractType { // abstract
//....
}
template <class T>
class Type1 : public AbstractType<T> {
//....
}
And later on, can I use these classes like this:
AbstractType<SomeClass>* var1 = new Type1<SomeClass>();
Thx for help.
...
I have a simple 2 object inheritance defined in an EF model, Person <- User.
Person is the base entity/class, it is not abstract, and it contains fields like firstname, lastname, email.
User is the derived entity/class, and contains fields like username, lastlogin, islockedout.
The database uses a table-per-type schema, so there is ...
Hey guys,
I'm stuck with what seemed to be a very simple task at the very beginning. I have a class hierarchy each class in which can define its own validation rules. Defining validation rules should be as simple as possible. Here is what is almost what is needed:
class HierarchyBase
{
private List<Func<object, bool>> rules = new ...
This is another of those SCJP questions. The code below prints Alpha:fooBeta:fooBeta:barBeta:bar, and I don't understand why the first foo call picked Alpha's foo instead of Beta's. If the Alpha.foo parameter is changed to String instead of String..., then the output is Beta:fooBeta:fooBeta:barBeta:barwhich makes sense.
My understanding...
Why do all Scala classes inherit from ScalaObject although that trait is completely empty and has no (visible?) functionality compared to AnyRef, which does define additional methods?
Won't that slow down method calls like equals() or hashCode() because it will need to take another class into consideration (which might override the meth...
I have the following class & interface defined:
public interface A {
}
public class B implements A {
}
I have a List of B objects that I need to cast to a List of A objects:
List<B> listB = new List<B>();
listB.add(new B()); // dummy data
listB.add(new B()); // dummy data
listB.add(new B()); // dummy data
List<A> listA = (List<A>...
Hi,
There is a C code, which we are trying to convert into C++ code. There were two inheritance hierarchies, which were managed by C through switch..case. That has been converted to use virtual functions in C++. Now at one point these two hierarchies have to get related. For example class A relates to A1, class B relates to B1 .... wh...
Hi
Level: Beginner
I'm doing my first steps in Object Oriented programming. The code is aimed at showing how methods are passed up the chain. So when i call UG.say(person, 'but i like') the method say is instructed to call class MITPerson. Given that MITPerson does not contain a say method it will pass it up to class Person. I think t...
Hello All,
I have the following entities
public abstract class ProductAttribute
{
public virtual long Id { get; private set; }
public virtual string Name { get; set; }
}
public class TextAttribute : ProductAttribute
{
public virtual string Value { get; set; }
}
and
public class Product
{
public virtual long I...
hey everyone :)
i am a new programmer in c++. and i am using templates for the first time.
i have an abstract class and another class extending it. but all the protected members of the abstract class are not recognised by the other class:
class0.h:
template<class T>
class class0 {
protected:
char p;
public:
char getChar();
}...
I've recently learned like 3 new languages and I'm starting to get them confused. I haven't worked Java in doing anything particularly complex (outside of android) in a couple years. I'm having trouble remembering if this is possible:
I'm subclassing ArrayList mainly so I can keep the arraylist ordered. I'm trying to override the add(ob...