class

C# Classes: What implications?

Possible Duplicate: Prefer composition over inheritance? Say I have this class: public class ndata { public int sal; public double cont; public string mytype; } I then have a choice of doing this: public class mydataTWO : ndata { public string a; public DateTime d; } or I can do this: pub...

How to create a new instance of the same class as the other object?

Having a object x which is an instance of some class how to create a new instance of the same class as the x object, without importing that all possible classes in the same namespace in which we want to create a new object of the same type and using isinstance to figure out the correct type. For example if x is a decimal number: >>> fr...

Sharing class variables between the instance and the class itself when extended within a module

I'm trying to figure why this code: class BaseClass end module Extensions def self.included(base) base.extend(ClassMethods) end module ClassMethods def message(message) @@message = message end end end BaseClass.send(:include, Extensions) class ExtendedClass < BaseClass message "hello world!" def say_me...

coder encodeObject

Consider the following code [coder encodeObject: properties forKey:@"properties"]; Are there any restrictions on what kind of object is passed as an argument to encodeObject? Can it be an object from a custom class? ...

Why isn't this classprop implementation working?

Based on a question I previously asked, I tried to come up with a class property that would allow setting as well as getting. So I wrote this and put it in a module util: class classprop(object): def __init__(self, fget, fset=None): if isinstance(fget, classmethod): self.fget = fget else: sel...

Assign derived class to base class

Is it safe to do the following or is it undefined behaviour: class Base { private: int a; }; class Derived : public Base { private: int b; }; Base x; Derived y; x = y; // safe? Do the extra bits in derived classes just get sliced off? ...

how to extend javascript classes

Why Child class doesn't have echo() method? Parent = function(){ this.name = 'abc'; } Parent.prototype.echo = function(){ alert(this.name); } Child = function(){ $.extend(this, Parent); } var x = new Child(); x.echo(); What should I do to inherit from parent class in Javascript? ...

Python, how to instantiate classes from a class stored in a database?

I'm using Django and want to be able to store classes in a database for things like forms and models so that I can easily make them creatable through a user interface since they are just stored in the database as opposed to a regular file. I don't really know a whole lot about this and am not sure if this is a situation where I need to u...

[C++] Is it a good idea to always return references for member variable getters?

If I have a class that has many int, float, and enum member variables, is it considered efficient and/or good practice to return them as references rather than copies, and return constant references where no changes should be made? Or is there a reason I should return them as copies? ...

Undefined reference to ClassName::ClassName

Hi all! I'm using Code::Blocks to build my project, which contains three files: main.cpp, TimeSeries.cpp, TimeSeries.h. TimeSeries.h provides declarations for the TimeSeries class as follows: template<class XType, class YType> class TimeSeries { public: TimeSeries(void); ~TimeSeries(void); }; Then TimeSeries.cpp contains: ...

Why am I getting this redefinition of class error?

Apologies for the code dump: gameObject.cpp: #include "gameObject.h" class gameObject { private: int x; int y; public: gameObject() { x = 0; y = 0; } gameObject(int inx, int iny) { x = inx; y = iny; } ~gameObject() { // } int add() { retur...

PHP return self as array of objects from within the class?

I'm using CodeIgniter to build a php web application, and I'm trying to use good OO practices - of which there appears to be many schools of thought. I specifically have a class biography_model to interact with a MySQL table. This data model has some class properties representing the columns in the table, but it also has some properties ...

getters and setters for custom classes

If you synthesize a custom class, do getters and setters get created for it? This is the custom class I created. // MyClass.h #import <Foundation/Foundation.h> @interface MyClass : NSObject <NSCoding> { NSString *string1; NSString *string2; } @property (nonatomic, retain) NSString *string1; @property (nonatomic, retain) NSS...

Why does my app crash

I made a class. This is the h file. // MyClass.h #import <Foundation/Foundation.h> @interface MyClass : NSObject <NSCoding> { NSString *string1; NSString *string2; } @property (nonatomic, retain) NSString *string1; @property (nonatomic, retain) NSString *string2; @end This is the m file // MyClass.m #import "MyClass.h" ...

Problems with my program involving arraylists, bufferedreader, methods, and overall forgetfullness of how java works.

Hello everyone. I am having difficulties with a program that I have been working on all day. I am trying to read a text file and read each line one at a time. Take that line and make an arraylist of the words of the line. then using the index of the arraylist define terms with it. public class PCB { public static void main(Strin...

When to use class::function or class->function, is there a preferred method?

Possible Duplicate: In PHP, whats the difference between :: and -> ? I've been seeing this class::function more in some code examples and thought it was the same as this class->function, but I wanted to know if there is a use case as to when I would use one over the other? ...

jQuery search for class

<ul class="list"> <li class="class1">text</li> <li class="class2">text</li> <li class="class3">text</li> <li class="class4">text</li> <li class="class5">text</li> </ul> How do I search for some class inside .list? Like: search for .class1 inside .list () { // do something if true } else { // do something...

How to masquerade child classes in parent class with autoloading (php)

I have a base class that is inherited by about ten subclasses. Most of these subclasses have very similar behavior, but I want to define specialized methods only for three of them. Is it possible to masquerade the existence of these classes, by autoloading the parent class every time an object of the child class is instantiated? This wa...

How to increment Date objects in C++

Hi everyone, I have an assignees that I've been working on and I'm stuck on the last function. use the function void Increment(int numDays = 1) This function should move the date forward by the number of calendar days given in the argument. Default value on the parameter is 1 day. Examples: Date d1(10, 31, 1998); // Oct 31, 1998 Date ...

How to call a method from another class in Java

So I have this class: public class Product { private String name, id, info ; private int quantity; public Product(String newName, String newID, String newInfo, Integer newQuantity){ setName(newName); setID(newID); setPrice(newInfo); setQuantity(newQuantity);} public void setName(String name) { this.name = name; } pub...