oop

C#: Any difference whatsoever between "(subtype)data" and "data as subtype" typecasting?

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 can't List<parent> = List<child>?

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? ...

Problem running functions from a DLL file using ctypes in Object-oriented Python

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"...

OOP design approach for two interacting classes

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...

OOP: composition samples please suggest which is better and why

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...

How to determine if an object is an object literal in Javascript?

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? ...

any good comparison for javascript vs. other OO languages?

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...

What exactly is the model in MVC

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...

How to break up a large class

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...

Is an abundance of void, parameterless functions a code smell?

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...

Solution to the lack of covariance with generics in c# 2.0 (BindingList)

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...

Best Practices for __get() and __set()

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....

Recommend some open source web frameworks for a fun project

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...

Question regarding MVC: SubClass for DB activity

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 ...

Multiple Symbol Reference problem in shared library of a factory design pattern

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...

database query's from class object with php

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...

pass MySQL link to a class method

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...

How to convert a Perl hash-of-hashes to a more flexible data structure?

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 should the constructor for an HTML parsing class do?

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...

php class method is preventing xml from working correctly

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...