class

How does Django Know the Order to Render Form Fields?

If I have a Django form such as: class ContactForm(forms.Form): subject = forms.CharField(max_length=100) message = forms.CharField() sender = forms.EmailField() And I call the as_table() method of an instance of this form, Django will render the fields as the same order as specified above. My question is how does Django ...

Multiple Integer-type classes in C++

I often find myself using Integers to represent values in different "spaces". For example... int arrayIndex; int usersAge; int daysToChristmas; Ideally, I'd like to have separate classes for each of these types "Index","Years" and "Days", which should prevent me accidentally mixing them up. Typedefs are a help from a documnentation pe...

How to declare variables

A colleague of mine and I have been discussing how to declare variables in a function. Let's say you have a class called TStrings (using Delphi for the sake of explanation) that has at least one abstract method and a descendant class called TStringList which obviously implements the abstract method, but it introduces nothing else you ne...

What (not) to declare when implementing an interface with an abstract class?

I have an interface A, for which I have to supply a few different implementations. However, those implementations share some helper methods, so I moved those methods to an abstract base class. Interface A { void doX(); } abstract Class B implements A { protected void commonY() { // ... } @Override public abstract void doX(); } ...

What is the best way to access properties from the same class, via accessors or directly?

This is something I'm not much consistent about and always curious about what other people do. How do you access internal properties (private or public)? For example you've got this property : Private _Name As String Public Property Name() As String Get Return _Name End Get Set(ByVal value As String) _Nam...

What is the best way to emulate "classes" in Javascript? (with or without a framework)

Update: I've wikified this so it can become a more useful resource. What is the best way to emulate classes (and namespaces) in Javascript? I need to create a Javascript library and have limited experience with the language. I always thought that it had native support for classes, but it is less related to Java than I had assumed. I...

Can I extend a class using more than 1 class in PHP?

If I have several classes with functions that I need but want to store separately for organisation, can I extend a class to have both? i.e. class a extends b extends c edit: I know how to extend classes one at a time, but I'm looking for a method to instantly extend a class using multiple base classes - AFAIK you can't do this in PHP b...

Does Python have something like anonymous inner classes of Java?

In Java you can define a new class inline using anonymous inner classes. This is useful when you need to rewrite only a single method of the class. Suppose that you want create a subclass of OptionParser that overrides only a single method (for example exit()). In Java you can write something like this: new OptionParser () { publi...

Is it a bad practice to have multiple classes in the same file?

I used to have one class for one file. For example car.cs has the class car. But as I program more classes, I would like to add them to the same file. For example car.cs has the class car and the door class, etc. My question is good for Java, C#, PHP or any other language. Should I try not having multiple class in the same file or is it...

C++ developing a GUI - classes?

I do have to say I'm fairly inexperienced when it comes to C++, don't be too harsh on me. Recently stumbled unto the wonders of the win32 API and have chosen to practice using it (I'd rather not use MFC/wxWidgets/etc at this point, just for educational purposes). Well, my real question is: How do you properly code your win32 GUI stuff ...

How to implement classes which all use the same variables

Hi, I have 6 classes, which are all document types. All the document types have the same 8 fields. There is one class which consists of only these 8 fields. The rest of the classes have more fields. Some of these classes have the same fields (beside the 8 fields). Example: class Document: fields 1 to 8 class Form: fields 1 to 8 and ...

Do static classes cause performance issues on multi-core systems?

Hi folks, the other day a colleague of mine stated that using static classes can cause performance issues on multi-core systems, because the static instance cannot be shared between the processor caches. Is that right? Are there some benchmarks around proofing this statement? This statement was made in the context of .Net development (w...

Jquery: My class does not function during second call.

I am new to jQuery.just learn and use it for 3 weeks until now. I have written a class to organize stuff. I call my method with more than 2 events,but the event does not work during my trigger of the second event. there's nothing wrong with the selector. I think there's something missing in my class. I don't know. please help! here's the...

C# implementation multiple variables

Hi all, I have something like this: classes A to D all have variables var1, var2, var3, var4, var5 class A has an extra variable var6 class B doesn't have var6, but do have the variables var7, var8 class C is the same as B, but has an extra variable var9 class D only has an extra variable, var10 How should i implement this? The be...

What is the difference between holding object of a class and agregating them?

May be the questions sounds newbie, but I can not distinguish the difference between agregating and holding. What does it mean in terms of, let`s say, C++? I suppose when the object of class A holds (or instantiates) objects of class B, it uses it to perform some functions by itself. For example: class A { int state; public: A(int s...

Classes that have no member data

What do you do with classes that have no member data, only methods? Do you make them static? In my case it is an repository class that executes queries against the database. Maybe I got the repository pattern wrong... (It does implement an interface) ...

Accessing the Document class in AS3

How can instantiated classes access the Document class? Even after I name the Document class using the Properties bar in Flash, attempting to access it from other classes usually fails, saying "attempting to access an undefined property... One solution is always casting the Document class to itself! eg. Main(Main).globalMethod(); Bu...

Inheriting from ViewPage

Is it possible to inherit from both ViewPage and ViewPage<T>?? Or do I have to implement both. Currently this is what I have for ViewPage. Do i need to repeat myself and do the same for ViewPage<T>?? public class BaseViewPage : ViewPage { public bool LoggedIn { get { if (Vi...

Python - Using __getattribute__ method

I want to override access to one variable in a class, but return all others normally. How do I accomplish this with __getattribute__? I tried the following (which should also illustrate what I'm trying to do) but I get a recursion error: class D(object): def __init__(self): self.test=20 self.test2=21 def __geta...

Using OOP for combining lots of functions (sort of namespace) in PHP?

Hi, I am working with PHP and I am wondering how bad practise it is to combine lots of funtions into a class. I am aware of it's not the purpose of classes, but the reason why I would do this is to provide a namespace. How big impact does it make to initiate let's say 10 classes at the execution of a PHP script isntead of let's say 2 or...