I have an object that implements an interface. I want to call on the object's method if it is implemented. What's the best way in doing this?
Update
A few of you mentioned that my question was vague. Sorry about that. When i said "if it is implemented" i meant "if it is callable". Thanks for your answers and effort guys (or girls!). I'm...
Hello guys.
I built (just for fun) 3 classes to help me log some events in my work.
here are them:
class logMessage:
def __init__(self,objectName,message,messageType):
self.objectName = objectName
self.message = message
self.messageType = messageType
self.dateTime = datetime.datetime.now()
def...
I'm writing a class that returns both a DataTable and a IEnumerable. I cannot define the interface methods exactly the same except for return type. So, I wish I could create this interface (obviously, it doesn't compile):
interface IMyInterface
{
DataTable GetResults();
IEnumerable<string> GetResults();
}
So, h...
My program needs to do 2 things.
Extract stuff from a webpage.
Do stuff with a webpage.
However, there are many webpages, such as Twitter and Facebook.
should I do this?
def facebookExtract():
code here
def twitterExtract():
code here
def myspaceExtract():
code here
def facebookProcess():
code here
def twitterProce...
I read that early C++ "compilers" actually translated the C++ code to C and used a C compiler on the backend, and that made me wonder. I've got enough technical knowledge to wrap my head around most of how that would work, but I can't figure out how to do class inheritance without having language support for it.
Specifically, how do yo...
I 'm reading OOAD book and I found it hard to comprehend some topic, so I think I need some book about OOP. I found they talk about "Object-Oriented Software Construction" in my OOAD book so I go to amazon and read some comments that is vary.
I want to know is it worth to read this book or not, is it has another book can I walk though t...
When we get an objects that is actually are exceptions, we can do with them anything that we can do with ordinar objects in our language. We can pass them as an argument, we can store them in some collection and, what is the worst, we can return them as a result from the methods!
So there is a possibility for someone to write smelly cod...
Hi Friends,
here is the part if having error.
Fatal error: Using $this when not in
object context in
/pb_events.php
on line 6
line 6 is: $jpp = $this->vars->data["jpp"];
function DoEvents($this) {
global $_CONF, $_PAGE, $_TSM , $base;
$jpp = $this->vars->data["jpp"];
$cache["departments"] = $this->db->QFe...
What is the difference between aggregation, composition and dependency?
...
First of all, I have no idea if the title even reflects my question. I apologize and kindly request to change it if you have a better idea.
Now, the problem I have is mainly a design problem. I am not sure if what I want is a good practice but it's d*mn convenient.
I have an Interface called IMovement.
Two classes implement IMovement...
Maybe I'm thinking about this the wrong way but here's the idea:
Class A gets, as part of it's constructor, a pointer to class B and saves that pointer in a private variable. Class B exposes a public function, F. I'd like for class A and all classes that inherit from class A to NOT be able to call B.F.
The idea is that class A will i...
I'm having a QT/C++ problem with a simple QWidget program that draws an ellipse inside a child QWidget.
The program is composed of:
(1) A parent QWidget
(2) A child QWidget (used as the drawing surface for an ellipse)
(3) A draw QPushButton
Here is part of the code (QPushButton Slot and Signal code omitted for simplicity)
void Draw::...
I have a code that looks like this:
using (DC dc = new DC())
{
f(dc.obj, a);
}
void f(DC dc, int a)
{
...
dc.obj = a;
}
It doesnt work - complains about object reference and non-static fields. This is a console application, so it has Main() function. How should I make it work? I tried adding references as it asked:
I ha...
Hi,
I have method in a class that I need to make sure is only called on an object instance, and not as a class method.
I will probably do something like this:
# Edit: this is terrible, don't do this, it breaks inheritance.
sub foo
{
my ($self) = @_;
if (ref($self) ne __PACKAGE__) { return; }
...do stuff
}
But I'm thinking it...
I found this related question: http://stackoverflow.com/questions/279158/how-do-i-use-composition-with-inheritance
I would like to do the same with Objective-C, that is to say that a GenericView knows that its property obj is a GenericObject, and that a SpecializedView knows that the very same obj property is a SpecializedObject.
Here ...
Currently I am working with a custom business object layer (adopting the facade pattern) in which the object's properties are loaded from stored procedures as well as provide a place for business logic. This has been working well in the attempt to move our code base to a more tiered and standardized application model but feel that this ...
I'm working on a RoR app, but this is a general question of strategy for OOP. Consider the case where there are multiple types of references that you are storing data for: Books, Articles, Presentations, Book Chapters, etc. Each type of reference is part of a hierarchy where common behaviors sit at the most general point of inheritance, ...
I cant seem to grasp the proper concepts of a factory.
Can anyone help me code a simple test? I read some texts over the internet and cant code it the same way. Actually i cant understand the process. Copying code is easy, but i need to learn why this wont work.
class Factory:
def __init__(self):
self.msg = "teste"
de...
I used to use procedural-style PHP. Later, I used to create some classes. Later, I learned Zend Framework and started to program in OOP style. Now my programs are based on my own framework (with elements of cms, but without any design in framework), which is built on the top of the Zend Framework.
Now it consists of lots classes. But th...
I have the habit of always validating property setters against bad data, even if there's no where in my program that would reasonably input bad data. My QA person doesn't want me throwing exceptions unless I can explain where they would occur. Should I be validating all properties? Is there a standard on this I could point to?
Exampl...