class

Python: Get class name from instance?

Example: class Class1: def __init__(self): self.x = Class2('Woo!') class Class2: def __init__(self, word): print word meow = Class1() How do I derive the class name that created the self.x instance? In other words, if I was given the instance self.x, how do I get the name 'Class1'? Using self.x.__class__.__na...

PHP extending class properties

Hi, I have two classes in a PHP application, B extending A for example. Class A has a function which returns some of its other properties in the form of an array of SQL insert queries eg Class A { $property_a; $property_b; $property_c; $property_d; function queries() { $queries = array(); $queries[] = "INSERT INTO xxx VALUES " . $this-...

What are guard methods/classes?

i just noticed the guard method/class mentioned in this question and i don't really get the concept from the answers. And alas, Jon Skeet's link to an MS site never loaded. A few quick Google searches seemed to yield only products, not software engineering concepts. Any explanation and/or samples would be appreciated. (Especially from t...

Pythonic way to only do work first time a variable is called

Hello, my Python class has some variables that require work to calculate the first time they are called. Subsequent calls should just return the precomputed value. I don't want to waste time doing this work unless they are actually needed by the user. So is there a clean Pythonic way to implement this use case? My initial thought was ...

PHP error_log performance issues

Hi, I've been trying to write an error handling class that I can use on sites, that will email me in the event of an error. Problem is, when I profile the application, it's choking on the error_log function. Here's my code (omitting the class: class ErrorHandler { private static $instance; private static $mail; private function __clone(...

How will I do a property drill down?

How will I know if an object instance is a property or a sub property of another object instance? for example I have this class structure: public class Car { public Manufacturer Manufacturer {get;set;} } public class Manufacturer { public List<Supplier> {get;set;} } public class Supplier { string SupplierName {get...

Why is this simple python class not working?

Hi, I'm trying to make a class that will get a list of numbers then print them out when I need. I need to be able to make 2 objects from the class to get two different lists. Here's what I have so far class getlist: def newlist(self,*number): lst=[] self.number=number lst.append(number) def printlis...

Get class value of element having multiple classes assigned using jquery.

I need to add and delete class on an element having multiple classes: This is the html: <div class="heading"> more html code here </div> I want to add class and get value of the added class. Can I do this? If not, how can a new class be added or removed? if ($(".heading").attr('class') == 'hidden') then $(".heading").removeClass('h...

How should i use a jar file ?

I have a jar file which contains some classes those which i want to use in my project. I am working in command line and not in eclipse. Please tell me how i should use those classes in the jar file for my project. ...

How to initialize a class?

The problem is really simple, I have a class "Stock", I want to load its property "StockName", "StockCode' from the db. so which patten should I use? pattern 1) Use service class to create it public interface IStockService{ Stock GetStock(string stockCode); void SaveStock(Stock stock); } p...

Exposing a same class twice using WCF

Hi, I have a 2 WCF services that are exposing the same object. Lets say the first service (SerA) exposes a class (classA) and the second service (SerB) which adds the filled classA also exposes this class (as this class is included in the parameters) Now when I retrieve the classA from SerA, it is concatenated with a namespace SerA.cla...

Use of .apply() with 'new' operator. Is this possible?

In JavaScript, I want to create an object instance (via the new operator), but pass an arbitrary number of arguments to the constructor. Is this possible? What I want to do is something like this (but the code below does not work): function Something(){ // init stuff } function createSomething(){ return new Something.apply(null...

Python: How do I make a subclass from a superclass?

In Python, how do you make a subclass from a superclass? ...

PHP, create_function or evalute it at runtime?

Hi all, i have a class with some method that depend by one parameter. What is the best way to write this method? Example: First way class Test{ var $code; function Test($type){ if($type=="A"){ $this->code=create_function(/*some args and some code*/); } else if($type=="B"){ $this->code=create_functi...

How do I compile asp.net webforms partial classes into a dll file?

If I use this code vbc /t:library /r:System.dll,System.Data.dll,System.Web.dll,Cooperator.Framework.Web.dll, DateRangePicker.dll,DateRange.dll,conexiones.dll, abmbancos.aspx.vb I can compile the codebehind file of an asp.net webform page into a dll file, as long as the codebehind file is declared with a regular class instead of a parti...

How can I reference a method from another class without instantiating it?

I don't want to create an object because it won't affect my visible form. How can I call a method so it does its thing in the visible side of things. public class foo { public void SetString(string foo) { label1.Text = foo; } } Inside another class: foo X = new foo(); X.SetString("testlololol"); This will set the la...

How do you find all implementations of an interface, in code?

My question is very similar in concept to this question. However, I was wondering how I would programmatically identify every class in a given namespace that implements a specific interface in a method (so I can add an object of each to a List), similar to how the Stripes Framework (in Java) finds all the classes that implement the Actio...

Is there any equivalent of C#'s Assembly.GetExecutingAssembly() in ActionScript 3?

Is there any equivalent of C#'s Assembly.GetExecutingAssembly() in ActionScript 3? I am attempting to iterate over each class in a namespace that implements a specific interface. ...

Multi Threading locks and monitor class not working

I have a file that is read and written to. I need to make sure when its been written to, nobody else will try to write to it. I put a lock on the whole function which allows to either read or write but I still get errors such as The process cannot access the file 'FILENAME' because it is being used by another process. public static TY...

[Ruby] Declaring instance variables iterating over a hash!!

Hi, i want to do the following: I want to declare the instance variables of a class iterating over a dictionary. Let's assume that i have this hash hash = {"key1" => "value1","key2" => "value2","key3" => "value3"} and i want to have each key as instance variable of a class. I want to know if i could declare the variables iterating o...