Hello!
I'd like to write a generic method that creates a new instances of a specified Type. I tried
protected T CreateNew<T>()
where T : new()
{
return new T();
}
This works, but only if I specified the type at compile time, just like
var x = CreateNew<Point>();
The point is, that I need to do something like this
ISomeInte...
For instance in C# or Java, you always have a main() method used to get your program running. What do you name the class that it is in? Some ideas I would use would just be "Program" or the name of the program itself. What would be considered conventional in this case?
...
Would some OO guru mind explaining the significance of these two keywords--what they do and for which context is one or the other preferable?
...
I'm not quite sure how to explain this (that's why the title is kinda weird) but I'll have a go. Basically I'm doing some Oject-Oriented Design and I want to represent various different types of object, each of which can have various actions which it can perform. An example might help: things such as a File which can have delete, rename ...
Hi Everyone,
I'm having some problems getting my object to gracefully fail out if an invalid parameter is given during instantiation. I have a feeling it's a small syntax thing somewhere that I simply need fresh eyes on. Any help is more than appreciated.
class bib {
protected $bibid;
public function __construct($new_bibid) {
...
I have a method which constructs an object, calls an Execute method, and frees the object. The type of object is determined by a TClass descendant passed into the method.
Note this is Delphi for Win32 I am talking about, not .NET.
Edit: I should point out that this is Delphi 2006, as it has been noted in answers below that in future ver...
Me and my friend had a little debate.
I had to implement a "browser process watcher" class which invokes an event whenever the browser that is being watched (let's say Internet explorer) is running.
We created a "Process watcher" class, and here starts the debate:
He said that the constructor should only accept strings (like "iexplore....
I've been hearing and reading about cases when people had come across cases of overused design patterns. Ok, missused design patterns are understandable phenomenon. What does it actually mean overused design patterns?
Do you have any examples and why do you think there are too many patterns?
...
I've got a game engine where I'm splitting off the physics simulation from the game object functionality. So I've got a pure virtual class for a physical body
class Body
from which I'll be deriving various implementations of a physics simulation. My game object class then looks like
class GameObject {
public:
// ...
private:
B...
I want to create a static class in PHP and have it behave like it does in C#, so
Constructor is automatically called on the first call to the class
No instantiation required
Something of this sort...
static class Hello {
private static $greeting = 'Hello';
private __construct() {
$greeting .= ' There!';
}
p...
I have a vb.net solution with a web reference to a webservice. Now I need another property in the designer generated code.
This has the drawback, that once you update the web reference, your added code will be overitten.
What is the best way to add a property to the class?
...
In your object-oriented language, what guidelines do you follow for grouping classes into a single file? Do you always give each class a seperate file? Do you put tightly coupled classes together? Have you ever specified a couple of implementations of an interface in one file? Do you do it based on how many lines of code the implementati...
I believe, that the usage of preprocessor directives like #if UsingNetwork is bad OO practice - other coworkers do not.
I think, when using an IoC container (e.g. Spring), components can be easily configured if programmed accordingly. In this context either a propery IsUsingNetwork can be set by the IoC container or, if the "using networ...
I'm learning Java (and OOP) and although it might irrelevant for where I'm at right now, I was wondering if SO could share some common pitfalls or good design practices.
...
I have a tree control in my GUI (with naturally lots of GUI/platform specific functions to handle the nodes).
I have a data model with its own complex set of nodes, children, properties etc..
I want the tree to display a representation of the model, be able to send messages to the nodes inside the model and be told to redraw itself when ...
I have a requirement to save an image file in various formats.
The list of formats is subject to change quite often, so I wish the saving would be very extensible.
Also, the saving can take place in many places (hard disk, ftp, http, etc). The list of saving locations is going to change very often too.
I thought I would use a base Image...
I'm creating an implementation that performs conversion from one form to another.
The design problem I am facing now is whether the Encoder and Decoder API should be in one interface or in separate ones. e.g. Apache MINA uses separate interfaces
I am currently doing something like this:
interface Convertor
{
A encode( B b );
...
How do these 2 classes differ?
class A():
x=3
class B():
def __init__(self):
self.x=3
Is there any significant difference?
...
I've been studying C# for a couple of years, reading voraciously, even taking a few C# data access courses from Microsoft. I've also been reading books on OOP. I'm coding a web-based database application at work. While my job title is not "programmer", I'm fortunate enough to be able to work on this as a side project. I coded in Basi...
In the same line as Database Normalization - is there an approach to object normalization, not design pattern, but the same mathematical like approach to normalizing object creation. For example: first normal form: no repeating fields....
here's some links to DB Normalization:
http://en.wikipedia.org/wiki/Database_normalization
ht...