I have a situation where an object A has a reference to object B. B also has a reference back to A. For the sake of simplicity, let's say that A and B are of the same type. How do I ensure that when I update the reference on A, that the update will be reflected on B as well (and vice versa)?
An example of an interface of such a type:...
What is the correct way of learning OOP deeply?
...
What is the preferred method to achieve the C++ equivalent of instanceof?
...
Just wanted opinions on a design question. If you have a C++ class than owns other objects, would you use smart pointers to achieve this?
class Example {
public:
// ...
private:
boost::scoped_ptr<Owned> data;
};
The 'Owned' object can't be stored by value because it may change through the lifetime of the object.
My view of it ...
I'm trying to get a grip on the OCaml language syntax and am having some trouble with applying some OOP structures. My goal with the below code is to have a class bar that inherits from a virtual class foo. The virtual class contains three virtual methods that I hope to take an instance of a "player" object as a parameter. When I compile...
I'm having trouble with lists in OCaml. I've read conflicting statements saying whether or not the lists can be modified at runtime. Can the cons operator be used at runtime?
Additionally, why is a doberman (see below) allowed to be in a list of chihuahuas? How would one go about adding another chihuahua onto the list (as attempted with...
Here I have the start of a news posting app I'm working on in ruby. Creating an article works fine, but I'm lost as to how to retrieve one. I'd like my Article.get method to return an article object,.. but it seems the only way to do this is to make all the Article attributes writable, which I don't really want to do. Are there any bette...
I'm trying to figure out how to best lay this out. I'll explain what I have now, but I'm wondering if there is a better way to do this.
I have a class Section that has basic properties: Name, Description, et.al. I use a list of Sections for the users to choose from. They can add a Section as many times as they want to a Parent object an...
While designing an interface for a class I normally get caught in two minds whether should I provide member functions which can be calculated / derived by using combinations of other member functions. For example:
class DocContainer
{
public:
Doc* getDoc(int index) const;
bool isDocSelected(Doc*) const;
int getDocCount() const...
I'd appreciate people's thoughts on a dilemma I've been struggling with ever since ASP.Net came out.
In classic ASP, the layers of code were minimal. The ASP page contained HTML and script combined. The COM components contained business logic and DAO infrastrcuture. The asp pages themselves were messy, but everything was in one place...
Let's say my program is always passed a string of characters that represents a data table in Wiki syntax. Something like:
{||Client:||ABC|-|Contact:||Joe Smith|-|Current revision:||1.0||}
I don't want each one of my specific Wiki table objects (e.g., ClientContactTable, CustomerOrderTable, etc.) to know how to parse out | and - and...
So lets say I have this interface:
public interface IBox
{
public void setSize(int size);
public int getSize();
public int getArea();
//...and so on
}
And I have a class that implements it:
public class Rectangle implements IBox
{
private int size;
//Methods here
}
If I wanted to use the interface IBox, i can't act...
I am creating an abstract class. I want each of my derived classes to be forced to implement a specific signature of constructor. As such, I did what I would have done has I wanted to force them to implement a method, I made an abstract one.
public abstract class A
{
abstract A(int a, int b);
}
However I get a message saying the a...
I've always been of the opinion that large switch statements are a symptom of bad OOP design. In the past, i've read articles that discuss this topic and they have provided altnerative OOP based approaches, typically based on polymorphism to instantiate the right object to handle the case.
I'm now in a situation that has a monsterous s...
Every time I come across an implementation of the singleton pattern or any static classes (i.e. classes with (almost) only static members) I wonder whether this isn't actually a hack and therefore heavy abuse of the principle of classes and instances just to design single objects instead of designing classes and creating a single instanc...
I am just starting to learn design patterns and I have two questions related to the Decorator...
I was wondering why the decorator pattern suggests that the decorator implement all public methods of the component of which it decorates?
Can't the decorator class just be used to provide the additional behaviors, and then the concrete com...
Hello anyone. Here is the situation. I have two classes: Action, and MyAction, last one is declared as:
class MyAction extends Action {/* some methods here */}
All i need is method in Action class(only in it, cuz there will be a lot of inherited classes, and i don't want to implement that method in all of them), which will return clas...
Hi All,
I want to develop a process() method. The method takes some data in the form of a data class, and processes it. The data classes are similar, but slightly different.
For example we have the following classes of data processDataObject_A, processDataObject_B and processDataObject_C.
Is it better to overload the method:
void p...
The docs (Exporter and perlmodlib) say:
As a general rule, if the module is
trying to be object oriented then
export nothing.
But then perlmodlib also says:
Standard, bundled modules are all
expected to behave in a well-defined
manner with respect to namespace
pollution because they use the
Exporter module.
So I w...
I've lately been thinking a lot about alternatives to the class-based approach to object-orientation.
One thing which bugs me in today's languages is that we often use static classes / singletons to design single (global) objects because there isn't any other way to do it, so in my opinion it's rather a hack than a feature.
Another thing...