class

Many instances of a class

I am trying to write a life simulation in python with a variety of animals. It is impossible to name each instance of the classes I am going to use because I have no way of knowing how many there will be. So, my question: How can I automatically give a name to an object? I was thinking of creating a "Herd" class which could be all the...

Quick Java Question: Instantiating a given class only from another?

My problem is thus: I need a way to ensure only one given class can instantiate another. I don't want to have to make the other a nested inner class or something dumb like that. How do I do this? I forget offhand. ...

How do I fetch all methods from a given namespace?

hello I want all the Method-ClassName from namespace like i have system.windows.Forms wehen in visual studio we rigt system.windows.Forms. it will suggest box of all the related method,class,enum extra i need to fetch the same ,how can i do that in C# Thanks ...

What is for the Index option in TRemotable derivated classes?

When WSDL importer wizard generates the interfaces, all properties have the Index option, but reading the code and the InvokeRegistry unit, I can't found what is that for, anyone know if it is really necessary? Like this Login = class(TRemotable) private [...] published property User: string Index (IS_OPTN) read GetUser ...

Optimal solution for struct with more than 16 bytes

I have a type which I consider use it as struct. It represents single value It is immutable But the problem is, it has 6 fields of int. So which solution I should use for this type? keep using struct? change to class? or pack 6 integers into an array of int, so it has only one field EDIT Size of struct with 6 integer fields is ...

Is Try-Finally to be used used sparingly for the same reasons as Try-Catch?

I just finished reading this article on the advantages and disadvantages of exceptions and I agree with the sentiment that Try-Catch blocks should not be used for "normal" control-flow management (don't use them like a goto). However, one author made (good) points about Maintainability and especially Performance that made me wonder abou...

Uml class diagram enum

Hi I am modeling a class diagram. An attribute of a class is an enumeration. How do i model this? Normally you do something like this: - name : string But how to do this with an enum? Thnx in advance :) ...

PHP classes: Need help to inherit two classes

I need help in designing my PHP classes where I need to extend from multiple classes. I have a general class, Pagination.php that does all sort of pagination and sorting. All other classes will use this for pagination. To make my life easier, I made a class generator that generates a class from MySQL table. All the properties, getters,...

How to cast member variable pointer to generic type in C++

I have code similar to this in my application: class A { public: int b; } class C { public: int d; } void DoThings (void *arg1, MYSTERYTYPE arg2); A obj_a; C obj_c; DoThings(&obj_a, &A::b); DoThings(&obj_c, &C::d); The question is - What should MYSTERYTYPE be? neither void* nor int work, despite the value &A::b being printed j...

Dynamically Create Subclass

I am using Kohana and just found this piece of code in their autoloading method // Class extension to be evaluated $extension = 'class '.$class.' extends '.$class.'_Core { }'; // Start class analysis $core = new ReflectionClass($class.'_Core'); if ($core->isAbstract()) { // Make the extension abstract $extension = 'a...

Is referencing an implementing base type in an interface a code smell?

I'm faced with a design decision that doesn't smell to me, but gives me pause. Take a look at the following code sample: public interface IGenerator { ///<summary> /// Combines two generators; performs magic as well /// </summary> BaseGenerator Combine(BaseGenerator next); ///<summary> /// Does what a generator does. ///...

Calling methods of "parent" component in Java

I have the following situation I think would be best to show in sample program code. I have a Java class that extends JPanel. In this class are two objects which are two more JPanels. In one of the JPanel objects is a JTable object. I added a listener to this JTable that detects a double click. When it detects a double click, I want...

Domain Entity Property Names

For domain entities, should property names be prefaced with the entity name? I.E. my class Warehouse has a property WarehouseNumber. Should that property be named WarehouseNumber or simply Number? Thoughts? ...

Class vs Struct for data only?

Is there any advantage over using a class over a struct in cases such as these? (note: it will only hold variables, there will never be functions) class Foo { private: struct Pos { int x, y, z }; public: Pos Position; }; Versus: struct Foo { struct Pos { int x, y, z } Pos; }; Similar questions: http://stackov...

C++: Dynamically loading classes from dlls

For my current project I want to be able to load some classes from a dll (which is not always the same, and may not even exist when my app is compiled). There may also be several alternative dll's for a given class (eg an implementation for Direct3D9 and one for OpenGL), but only one of the dlls will be loaded/used at any one time. I ha...

SerializationException when setting instance of one class to another

I'm trying to pass an instance of a class between two separate classes, like the following. //classes public class A { public string name; public string data; } public class B : MarshalByRefObject { public A _a; } public class C : MarshalByRefObject { public A _a; } //main program static void Main(string[] args) { B _b = ...

Multiple inheritence in C++ leading to difficulty overriding common functionality

In a C++ physics simulation, I have a class called Circle, and Square. These are Shapes, and have a method called push(), which applies force to it. There is then a special case of Circle, call it SpecialCircle, in which push() should exhibit slightly different properties. But in fact, there is also SpecialSquare() which should exhibit...

Singleton in PHP

am working on a web app in PHP that requires users to register and login with their credentials. However, i am using the singleton pattern in all my PHP class files. I have something bothering my mind that i would like to clarify. For instance, When the application goes live and we have several users on the site at the same time, doing...

How can I assign a new class attribute via __dict__ in python?

I want to assign a class attribute via a string object - but how? Example: class test(object): pass a = test() test.value = 5 a.value # -> 5 test.__dict__['value'] # -> 5 # BUT: attr_name = 'next_value' test.__dict__[attr_name] = 10 # -> 'dictproxy' object does not support item assignment ...

Storing an SqlDataReader-object in C#/ASP.NET?

I'm currently writing a C#-class in my ASP.NET (3.5) application to handle all database-queries. Some of the methods are there to make a select-query to the database. Inside the method i simply have a SqlDataReader r = command.ExecuteReader(); to fetch the data. I now want r to be returned by the method, but when i close the database-co...