Consider a rectangle with sides X and Y, and area Z such that Z=X*Y.
The rectangle has to be modeled into the cleanest OOD which will supply the following two services,
Given side X and side Y, calculate area Z.
Given side X and area Z, calculate side Y.
One possible design I was thinking on is,
A class Rectangle that have private...
In C++, is it possible to have a child class "hide" a base class' static fields and methods? (i.e. A has a field named ABC of type int, B:A and B has a field named ABC of type int)
...
Here is a Django model I'm using.
class Person(models.Model):
surname = models.CharField(max_length=255, null=True, blank=True)
first_name = models.CharField(max_length=255, null=True, blank=True)
middle_names = models.CharField(max_length=255, null=True, blank=True)
birth_year = WideYear(null=True, blank=True)
birth...
With the display list in Actionscript 3.0, I'm often inclined to have children add themselves to their parent because they often already have that reference. That would look like:
_myParent.addChild(this);
or when removing...
this.parent.removeChild(this);
By the wording of the addChild() syntax, this way seems backwards -- ...
I'm making a Perl website, and I'll using Template Toolkit (for the view), a whole bunch of objects for DB interaction and business logic (the model), but I'm wondering: should the controllers be OO?
I feel like they should, just for consistency, but it also feels it might be a bit redundant when I'm not interacting with the controllers...
Which is the better practice and why?
bool IsTodayMonday { get { return DateTime.Now.DayOfWeek == DayOfWeek.Monday; } }
Or
bool IsTodayMonday()
{
return DateTime.Now.DayOfWeek == DayOfWeek.Monday;
}
...
I am looking for a method to share resources among siblings. For example, if the parent class has a File handler, is there a way in which I need to open and close a file only once.
Seems like a simple problem but I can't figure it out. I know I can pass the resources as parameters but is there a more elegant way ?
...
In the example module below, the getters and setters are generated by adding anonymous subroutines to the symbol table. After the methods have been created in this manner, will the resulting code be functionally equivalent (in terms of behavior, speed, etc.) to a module with manually-written getters and setters, or does this approach hav...
Hey. I remember reading somewhere about a programimng paradigm that has very tough restrictions about OO. It forbids nested ifs and elses entirely, avoid functions in the global namespace not associated with a class, and stuff like that. It's supposedly pretty famous. Does anyone know how it is called? Thanks.
I'll give an example. This...
In Python and Pyqt - I've got a simple class which instantiates a Label class and a GroupBox class.
According to docs, passing the Groupbox to the Label upon creation should make the Groupbox the parent of Label. However, I must be missing something simple here. When I create the GroupBox it's fine, when I create the Label however - it...
What are advantages of using UserDict class?
I mean, what I really get if instead of
class MyClass(object):
def __init__(self):
self.a = 0
self.b = 0
...
m = MyClass()
m.a = 5
m.b = 7
I will write the following:
class MyClass(UserDict):
def __init__(self):
UserDict.__init__(self)
self["a"] = 0...
In an OO component, when you have only one implementation available for an class and that class is not 'published' to other components, is it still advisable to have an interface and work with the interface instead?
I am fully aware of 'programming to an interface' design principle and also use it extensively.
Lately, I have been obs...
I'm trying to maintain state on an object by doing something like this:
obj = function() {
this.foo = undefined;
this.changeState = function () {
(function () { this.foo = "bar" })(); // This is contrived, but same idea.
};
};
I want to set the instance variable foo to "bar" when I call the changeState method.
...
I met a problem like this.
class A have a list of class B. A have choose one of B, and call its method. So A depends on B.
But when a timer ( not a real timer, just a mimic clock ) fires, B have to tell A that "I am done", so A can choose another B to work, which means B has to know A also.
This is a "two way 1-n relationship" and ...
Hi there
I am exploring this and see if this one make sense. For instance I have 2 abstract objects called: Customer and Tender. The relationship is that Customer can have many Tenders.
My question is how to achieve like this on the TestClient app:
1) customer.InTender[0].ID = ???
What method to handle to handle this? Do I need to p...
Let's say I've got an event listener function that is listening for an event that will never be called again throughout the lifespan of the program. The listening object will never need to be garbage collected.
How much memory does this use?
If it's negligible, I'd rather not remove the listener because having the removeEventListener() ...
I have a pretty large site and every page is built from several included files, my site is 100% in a procedural format and I am trying to learn to use classes and a more OOP approach in PHP.
Currently my site has a header file that is included into every page, in this header is a mysql connection that is made and last the duration of ...
If one has a object which can persist itself across executions (whether to a DB using ORM, using something like Python's shelve module, etc), should validation of that object's attributes be placed within the class representing it, or outside?
Or, rather; should the persistent object be dumb and expect whatever is setting it's values t...
3 class, A contains B, B contains C. So user want to use some service of C, there are two choice:
First, more encapsulation:
class A:
def newMethod(self):
self.b.newMethod()
class B:
def newMethod(self):
self.c.newMethod()
class C:
def newMethod(self):
#do something
pass
a.newMethod()
C...
I'm in a project that takes the Single Responsibility Principle pretty seriously. We have a lot of small classes and things are quite simple. However, we have an anemic domain model - there is no behaviour in any of our model classes, they are just property bags. This isn't a complaint about our design - it actually seems to work quite w...