Assuming I have an instance of an object that I know belongs to a subclass of a certain subtype passed to me through a reference of a supertype in C#, I'm used to seeing typecasting done this Java-like way (Assuming "reference" is of the supertype):
if (reference is subtype){
subtype t = (subtype)reference;
}
But recently I've come ac...
Why won't the following code work?
class parent {}
class kid:parent {}
List<parent> parents=new List<kid>;
It seems obvious to me. What's going on here?
...
Hello everyone!
I sure hope this won't be an already answered question or a stupid one. Recently I've been programming with several instruments. Trying to communicate between them in order to create a testing program.
However I've encoutered some problems with one specific instrument when I'm trying to call functions that I've "masked"...
What are the relative advantages / disadvantages of chaining classes together (or rather; using the results of one class to generate another), compared to nesting classes?
I'm trying to restructure my user / authentication system and am wondering whether;
myAuthClass should act as a utility and if log-in is successful, simply create a...
Please ignore language syntax, I want to discuss only OOPS here.
I will present here 2 code snippets, each of which is a sample of Composition (if I'm not wrong).
Problem Statement: I have an object which keeps the stats of an entity in the system. Let those stats be:
Name
LastName
Salary
*these fields can be anything, I just too...
Is there any way to determine in Javascript if an object was created using object-literal notation or using a constructor method?
It seems to me that you just access it's parent object, but if the object you are passing in doesn't have a reference to it's parent, I don't think you can tell this, can you?
...
I've just started learning javascript and noticing its attributes relating to other OO languages (weakly typed like php/tcl, has error handling and inheritance like java's model). When I was learning java there were several "C++ vs. Java" comparisons that really helped me wrap my head around the philosophy of the language.
Javascript do...
I'm slightly confused about what exactly the Model is limited to. I understand that it works with data from a database and such. Can it be used for anything else though? Take for example an authentication system that sends out an activation email to a user when they register. Where would be the most suitable place to put the code for the...
I have a large Shape class, instances of which can (should) be able to do lots of things. I have many "domain" shape classes which inherit from this class, but do not provide any different functionality other than drawing themselves.
I have tried subclassing the Shape class, but then all of the "domain" objects will still inherit this s...
So I'm looking over some code I've written and noticed that most of the function calls are parameterless and return void. They tend to use public properties instead of arguments and return values. This was an outgrowth of the architectural pattern I was using and I just wound up extending it. The canonical example of MVP passive view has...
It's a design question. I have a business object, and 5 business object types that are derived from it.
I also will have a class which has BindingList as a member. I will have 5 classes derived from it.
Since covariance doesn't work here, how would you structure the design to minimize code repetition? I could of course chuck the Bind...
Stemming from this question on using __get() and __set() to access private variables, I'd like to get the input on how they are used in general. I am wondering when or where would be the best time to use a overloading function, and where you have used one (if you have).
Just to be clear, we are talking about these functions: http://us2....
I maintain very dull in-house business software for a living. Technologies included here are Java, Struts, Spring MVC, jsp, wicket, and a few others. I think it's time to branch out and learn something new.
I am hoping to show myself with a side project that writing code can, in fact, be fun (in some plane of the universe), and that I...
I just recently dove into OOP & now MVC and am using this template engine : http://www.milesj.me/resources/script/template-engine
I am curious about one question on where to put my DB calls (I'm using a basic database wrapper class).
I've seen two ways done.
class Cart
/**
* Counts items in cart
* @return int
*/
public static ...
Hello,
I am trying to write a C++ implementation of factory design pattern. I would also like to do it using shared objects and dynamic loading. I am implementing a function called new_animal() which is passed a string. If the string is "dog", then it needs to see if a class dog is registered in shared object and create a dog object...
Hello,
My question is:
Can I still do query's from within an object like this:
$result = mysql_query ($q,$dbc)
or
trigger_error("Query: $q\n<br />MySQL Fout: " . mysql_error($dbc));
by passing the global dbconnection variable $dbc to the constructor
or is there a better way?
Or creating a singleton class for...
Here is my problem, i have a class with a ave method, i want to pass a Mysql DB link to it, so i create a new object from the class, and call the saveProperty method, and in my main file i created a MySQL connection and saved the link in a var called $db so when i call the method it's link this: saveProperty($db).
but insted of saving t...
In a quick-and-dirty Perl script, I have a data structure like this:
$tax_revenue{YEAR}{STATE}{GOVLEV}{TAX} = integer
The hash keys assume values like this:
YEAR: 1900 .. 2000
STATE: AK, AL, ... WY
GOVLEV: state, local
TAX: type of tax (income, sales, etc.)
In addition, the hash keys are unique. For example, no value for the TAX pa...
How much work is it reasonable for an object constructor to do? Should it simply initialize fields and not actually perform any operations on data, or is it okay to have it perform some analysis?
Background:
I was writing a class which is responsible for parsing an HTML page and returning various information based on the parsed informat...
Hello,
I have a problem that I cannot understand
I am trying to make my webservice work from a class.
I try'd to echo the xml from some function in a controllerclass, but that diddn't work.
So, I moved the xml around to a place where it did work.
That means that I placed it before the loader function is called. That's where it still w...