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...
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...
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...
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?
...
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...
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?
...
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?
...
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...
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?
...
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:
...
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...
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 ...
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...
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"
...
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...
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?
...
<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...
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...
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 ...
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...