class-design

Resolve a filename from another file

I can currently to the following: class SubClass extends SuperClass { function __construct() { parent::__construct(); } } class SuperClass { function __construct() { // this echoes "I'm SubClass and I'm extending SuperClass" echo 'I\'m '.get_class($this).' and I\'m extending '.__CLASS__; } } I would like to do som...

static const Member Value vs. Member enum : Which Method is Better & Why?

If you want to associate some constant value with a class, here are two ways to accomplish the same goal: class Foo { public: static const size_t Life = 42; }; class Bar { public: enum {Life = 42}; }; Syntactically and semantically they appear to be identical from the client's point of view: size_t fooLife = Foo::Life; size_...

Large Inner classes and private variables

One thing I've run into a few times is a service class (like a JBoss service) that has gotten overly large due to helper inner classes. I've yet to find a good way to break the class out. These helpers are usually threads. Here's an example: /** Asset service keeps track of the metadata about assets that live on other systems. Compl...

C#: Alias a class name?

i want to create an alias for a class name. The following syntax would be perfect: public class LongClassNameOrOneThatContainsVersionsOrDomainSpecificName { ... } public class MyName = LongClassNameOrOneThatContainsVersionOrDomainSpecificName; but it won't compile. Example Note This example is provided for convience only. Don'...

What is a good design pattern in C# for classes that need to reference other classes?

I am working on a business problem in C#.NET. I have two classes, named C and W that will be instantiated independently at different times. An object of class C needs to contain references to 0 ... n objects of class W, i.e. a C object can contain up to n W objects. Each W object needs to contain a reference to exactly 1 object of cla...

Nested Java enum definition - does declaring as static make a difference?

I have an interface - here's a nicely contrived version as an example: public interface Particle { enum Charge { POSITIVE, NEGATIVE } Charge getCharge(); double getMass(); etc... } Is there any difference in how implementations of this would behave if I defined the Charge enum as static - i.e. does this...

Serializing Name/Value Pairs in a Custom Object via Web Service

This is a very complicated question concerning how to serialize data via a web service call, when the data is not-strongly typed. I'll try to lay it out as best possible. Sample Storage Object: [Serializable] public class StorageObject { public string Name { get; set; } public string Birthday { get; set; } public List<NameValueP...

Should a c# class generate instances of itself?

I have a class that defines a CallRate type. I need to add the ability to create multiple instances of my class by reading the data from a file. I added a static method to my class CallRate that returns a List<CallRate>. Is it ok for a class to generate new instances of itself by calling one of its own constructors? It works, I just won...

Is it considered bad design to do lengthy operations in a constructor?

I am implementing a class to compare directory trees (in C#). At first I implemented the actual comparison in the class's constructor. Like this: DirectoryComparer c = new DirectoryComparer("C:\\Dir1", "C:\\Dir2"); But it doesn't feel "right" to do a possible lengthy operation in the constructor. An alternative way is to make the cons...

If abstract base C++ class is actually an interface, so it own no data members, is it obligatory to call base class constructor in derived class constructor?

I have a code: class AbstractQuery { virtual bool isCanBeExecuted()=0; public: AbstractQuery() {} virtual bool Execute()=0; }; class DropTableQuery: public AbstractQuery { vector< std::pair< string, string> > QueryContent; QueryValidate qv; public: explicit DropTableQuery(const string& qr): AbstractQuery(), qv(q...

How do you bring Denormalized Values Into your Business Objects?

I have two Tables. Order - With Columns OrderID, OrderStatusID OrderStatus - With Columns OrderStatusID, Description I have an Order Object which calls to the database and fills its properties for use in my code. Right now I have access to Order.OrderStatusID, but in my application I really need access to the "Description" field. How...

Not-Null constraints in POCO Objects

I am currently writing an financial application, and we have a pretty standard customer table. It consists of many mandatory fields, and some optional like Cell/Fax etc.. I'm using NHibernate as a ORM and have all the mappings right. It already works. I just wonder, how do I "express" in code that a field is not-null without commenting?...

What constitutes a rich domain model in a POJO/POCO?

What is the difference between A simple fields-accesors-mutators class A rich-modeled class What constitutes rich modeling in business-domain classes? ...

best name for object for collection of semantically-related inputs?

I'm writing an HTML form generation library. There's a top-level Form class, and at the bottom there are classes for each type of HTML form input object (Select, Textfield, Radio, etc.). There's a class in between, that holds groupings of 1 or more semantically related input objects. For example, one type of this class could be called '...

non-member non-friend function syntax

Is their a way to use a non-member non-friend function on an object using the same "dot" notation as member functions? Can I pull a (any) member out of a class, and have users use it in the same way they always have? Longer Explanation: Scott Meyers, Herb Sutter, et all, argue that non-member non-friend functions are a part of an obje...

'Desirable Characteristics of Design' in code complete

Here are the points that seem vague to me : "High-Fan in" : have a high number of classes that use a given class; good use of utility classes at the lower levels. "Low fan-out" : don't use too much other classes in a given class. Does that mean you can't even have a given class use several small utility class ? ...

"Public" nested classes or not

Suppose I have a class 'Application'. In order to be initialised it takes certain settings in the constructor. Let's also assume that the number of settings is so many that it's compelling to place them in a class of their own. Compare the following two implementations of this scenario. Implementation 1: class Application { Applic...

How do I resolve: "error C2039: '{ctor}' : is not a member of" in Visual Studio 2005?

I am extending a template class using C++ in Visual Studio 2005. It is giving me an error when I try to extend the template base class with: template <class K, class D> class RedBlackTreeOGL : public RedBlackTree<K, D>::RedBlackTree // Error 1 { public: RedBlackTreeOGL(); ~RedBlackTreeOGL(); and a second error when I try to inst...

What's wrong with Copy Constructors? Why use Cloneable interface?

When programming C++ we used to create copy constructors when needed (or so we were taught). When switching to Java a few years ago, I noticed that the Cloneable interface is now being used instead. C# followed the same route defining the ICloneable interface. It seems to me that cloning is part of the definition of OOP. But I wonder, wh...

iPhone Development - Creating a class like UIImagePickerController that returns data to parent

I have a situation where I have to take input from the user using multiple views (like Personal Information -> Professional Information -> Process Completed). I was wondering, how can I build a class like UIImagePickerController, which takes input from user and returns the data to parent class? Note that the view is also handled by this...