class-design

Handling mutable collection keys in C#

Let's say I have a simple class Cat in C#, with a Name property of type string. Now I need a collection class for my cats, so I decide to wrap a Dictionary<string, Cat> in a custom collection class. Basically, this class holds a private dictionary variable and adds or removes collection members as necessary, as well as indexing cats by t...

Should I place a built in Class (such as Date) as a separate class in my UML.

I'm creating a UML Class Diagram for an inventory system as part of a class assignment. I used members such as String and Date in a few of my Classes. My group members are saying that I should include a Date class because it is an object. My assumption is that we were using Java or some other language with a built in Date object. Do I...

Delegates, can't get my head around them

Hey, I'm looking for useful resources about Delegates. I understand that the delegate sits in the background and receives messages when certain things happen - e.g. a table cell is selected, or data from a connection over the web is retrieved. What I'd like to know in particular is how to use delegates with multiple objects. As far as ...

Are partial methods considered harmful?

In C# 3.0 Microsoft introduced support for something called partial methods. Do you use them? Can you describe how and why? Do you consider the use of partial methods good programming practice, or not? edit: Two people downvoted the question? I find that puzzling and amusing. Should I not be asking this? ...

Should a class have the same name as the namespace?

I'm designing a namespace to hold a set of classes that will handle user related tasks for a several different applications. (Log-in, authenticate etc) The problem is the namespace will be called Fusion.User but then it requires a class in that namespace that makes sense to call User. Should you have a class with the same name as the n...

OO Javascript constructor pattern: neo-classical vs prototypal

I watched a talk by Douglas Crockford on the good parts in Javascript and my eyes were opened. At one point he said, something like, "Javascript is the only language where good programmers believe they can use it effectively, without learning it." Then I realized, I am that guy. In that talk, he made some statements that for me, were...

OO Javascript: good way to combine prototypal inheritance with private vars?

In OO Javascript constructor pattern: neo-classical vs prototypal, I learned that constructors using prototypal inheritance can be 10x faster (or more) than constructors using the so-called neo-classical pattern with closures as proposed by Crockford in his "Good Parts" book and presentations. For that reason it seems like preferring p...

Programs to make class diagrams?

Hi, I know that visual studio has a class diagram designer built in, but I wondered if anybody knew of some other programs that are suitable for making class diagrams? Thanks! ...

What design should I use so a class can query one of it's ancestors?

I'm creating an object hierarchy that is representing a table that is draw on a control. My hierarchy looks like this : Table has multiple pages Page has multiple lines Line has multiple cells Cell has multiple glyph I want to have an option (a parameter) on the table to filter the column (cells) displayed. The client code can do some...

Should I create a separate class for this?

My project contains a lot of classes, a bunch of which can be described by XML files. Don't worry, it's not the logic or implementation in XML. It's a game, and an example would be that a game tile can be defined in XML, the image file, animation frames, etc. I'm going to end up having a bunch of functions that look like this: public ...

Class implementations in interface dll?

Hello, my problem: Inside an application, all interfaces are declared inside an own dll(project "interfaces", for example). Inside project interfaces, there are many class implementations, too. Now I need one of this implemented classes inside another project and get a ring dependency because this project is also a reference in projec...

Javascript data structures

Hi, I would like to know if it is possible to do something like this: if (mb == null || typeof (mb) != "object") { var mb = new Object(); } mb = { tests: { onAnimals: { test: function() { return ""; } } onHumans: { test: function() { r...

Visual Studio 2008 Class Designer - associations

We are attempting to use VS2008 Class Designer for a UML-like class diagram. However, when we create an "association" link between two classes, VS2008 is adding lines to our code! We do not want this. One reason we don't want this is that our idea of association (via a collection parrameter, etc.) is different than VS2008. For exam...

When should i use properties instead of object references?

For example if i have an Author class and a book class independently. We all know an author writes a book. What i would love to know when it's best to include the book as a reference object in the Author class or just include the book name? The reason for this question ties mainly to flexibility and easy maintenance. Update: What des...

Standalone functions in ASP.net

Never seen this done in asp.net, but never the less, can I define functions without being part of the class? What I would like to have is a utility library. Currently I have Utils class and every time I need to use it for things like populating drop down lists i have to create and init the Utils() object...any way around that hassle as...

Javascript: What is the preferred design for nested (inner) types?

I use Resig's makeClass() approach for constructors: // makeClass - By John Resig (MIT Licensed) // Allows either new User() or User() to be employed for construction. function makeClass(){ return function(args){ if ( this instanceof arguments.callee ) { if ( typeof this.init == "function" ) this.init.apply( this...

Javascript: why does jQuery do this: (function(){ ...});, and how does it work?

EDIT: I THOUGHT The jQuery source I was looking at did something like this: (function(){ var bunchOfVariables = 7; jQuery = " ....."; //.... }); I was wrong about that. Ignore this question. I don't understand what that does. Can someone please explain it? This is the very first line in jQuery-1.3.2.js. It ap...

Java: Return class (Not an instance)

Hi, Is it possible to return in a static method a class? I will explain... I have: public class A { public static void blah(){} } public class B { } I want to create a static method in B witch returns A. So you can do: A.blah(); And B.getA().blah(); This, without creating an instance of A. Just use it static methods. Is this ...

Accessing a function in a class from other classes

What I want to do is access the query function in my database class form anther class. Evey time a query is done I track the time it takes and add the the query count, I want to do that for all query's. The layout I have now is: Global ----------------------------- | | database class ...

Best way to implement class library containing standards which changes yearly

I want to create a class library for some standards. These standards are updated yearly (Not necessarily every year, may take 3-4 years also). I want to maintain older versions also. What is the best way to do it? Currently I am thinking of following structure: StandardName (namespace) --> Year(namespace) --> actual implementation of p...