I'm writing a Ruby class that extends TCPSocket. Assume it looks something like this:
class FooSocket < TCPSocket
def hello
puts 'hello'
end
end
I have a TCPServer listening for incoming connections
server = TCPServer.new 1234
socket = server.accept
When my server finally accepts a connection, it will return a TCPSo...
Hi there, I have a base class called Items and 3 derived classes, and within the Items base class i have a print function of the form
public void print(){
System.out.println("ID " + id + " Title " + title + " <" + year + "> ");
}
and within every derived class I call the Items print function through super.print(); which is...
Can I somehow force a derived class to always call the overridden methods base?
public class BaseClass
{
public virtual void Update()
{
if(condition)
{
throw new Exception("..."); // Prevent derived method to be called
}
}
}
And then in a derived class :
public override void Update()
{
...
I've been racking my brains over inheritance for a while now, but am still not completely able to get around it.
For example, the other day I was thinking about relating an Infallible Human and a Fallible Human. Let's first define the two:
Infallible Human: A human that can never make a mistake. Its do_task() method will never throw an...
Here is my situation:
I have an event driven system, where all my handlers are derived from IHandler class, and implement an onEvent(const Event &event) method. Now, Event is a base class for all events and contains only the enumerated event type. All actual events are derived from it, including the EventKey event, which has 2 fields: (...
Given the following classes:
class Foo
{
struct BarBC
{
protected:
BarBC(uint32_t aKey)
: mKey(aKey)
mOtherKey(0)
public:
const uint32_t mKey;
const uint32_t mOtherKey;
};
struct Bar : public BarBC
{
Bar(uint32_t aKey, uint32_t aOtherKey)
...
In my solution there's a few WCF services, each of them implementing it's own callback interface. Let's say they are called: Subscribe1, with ISubscribe1 and ICallback1, etc.
It happens there are a few methods shared among ICallbacks, so I made a following interface:
interface ICallback
{
[OperationContract]
void CommonlyUsedMe...
hi guys,
I am stuck with a problem about generic classes. I am confused how I call the constructor with parameters.
My interface:
Public Interface IDBObject
Sub [Get](ByRef DataRow As DataRow)
Property UIN() As Integer
End Interface
My Child Class:
Public Class User
Implements IDBObject
Public Sub [Get](ByRef DataR...
Just seen one tutorial saying that:
Class Dog
{
private string Name;
}
Class SuperDog:Dog
{
private string Mood;
}
Then there was an UML displaying that SuperDog will inherit Name as well. I have tried but to me it seems that only public members are inherited. At least I could not access Name unless it was declared as public.
...
I have a base class MessageHandler and 2 derived classes, MessageHandler_CB and MessageHandler_DQ.
The derived classes redefine the handleMessage(...) method. MH_DQ processes a message and puts the result in a deque while MH_CB processes the message and then executes a callback function.
The base class has a static callback functio...
I'm trying to extend a Java Swing component in Clojure, i.e. I want to extend a javax.swing.JComponent and add some custom methods implemented in pure Clojure in addition to all the standard inherited methods.
I've tried using "proxy" which works great if I just want a single instance (in the same way as an anonymous inner class). Howev...
I've run into a situation that I am not quite sure how to model.
EDIT: The code below now represent a working solution. I am still interested in nicer looking solutions, though.
Suppose I have a User class, and a user has many services. However, these services are quite different, for example a MailService and a BackupService, so singl...
Hi,
I'm working on a ruby project using Sinatra as a framework and have a question about extending classes.
Lets say I have a User class which is extended by an Admin, does the Admin have to be defined in User.rb? I've tried putting it in Admin.rb but I get an error saying:
admin.rb:1: uninitialized constant User (NameError)
Thanks....
Hi there,
I'm writing a spatial data structure and I have a doubt about what's the best NODE implementation.
According to my design I have an abstract node entity and three classes which inherit from it: EMPTYNODE, FULLNODE, INTERNALNODE.
The first one has no particular data.
The second one has 1 reference to a generic element.
The t...
Hi guys,
I'm writing a Project in Django where I've 5 kind of groups of Users:
Group1
Group2
...
Then I've a Model, Item which has many relation with users, the Item has one Owner (a User in Group1), a Customer (an User in Group2) and many RelatedUser (Users in Group3).
I'm wondering which is the correct way to write this relations...
Guys do we inherit from Object like from any other class (except of course that we don't have to explicitly state that) or there is some special privileges to Object class and it's not inherited as other classes?
...
Hello,
I want to create a class that can use one of four algorithms (and the algorithm to use is only known at run-time). I was thinking that the Strategy design pattern sounds appropriate, but my problem is that each algorithm requires slightly different parameters. Would it be a bad design to use strategy, but pass in the relevant par...
Hello, everyone.
I am having some trouble on a project I'm working on.
Here's the header file for the calor class:
#ifndef _CALOR_
#define _CALOR_
#include "gradiente.h"
using namespace std;
class Calor : public Gradiente
{
public:
Calor();
Calor(int a);
~Calor();
int getTemp();
int getMinTemp();
void setTe...
How to force QuerySet not to return instances of child models?
...
I have following scenario:
class my_base { ... }
class my_derived : public my_base { ... };
template<typename X>
struct my_traits.
I want to specialize my_traits all classes derived from my_base including: i.e.
template<typname Y> // Y is derived form my_base.
stryct my_traits { ... };
I have no problems to add any tags, members...