class-design

When is it best to use a new class rather than add to an existing class

I have a class called Player in the business layer of my web application. Player class has fields PlayerID, CategoryID and CountryID A function in Player Class calls a function in PlayerDB Class in the Data Access Layer which in turn calls a stored proc which returns data for PlayerID, CategoryID (foreign key to Category table) and Cou...

How can a C# class be written to test against 0 as well as null

BACKGROUND: I have a custom class written in C# (2005), with code similar to the following: public class Savepoint { public int iOffset; /* Starting offset in main journal */ public u32 nOrig; /* Original number of pages in file */ public u32 iSubRec; /* Index of first record in su...

How to decide between Composition and Generalization when designing objects and their relationships ?

I thought to seek this answer from stackoverflow community that how to decide to go for composition or generalization when we are designing classes. ...

Best place to check for property values.

Hi, Assuming you have a class Photo: class Photo { public string Title {get; set;} public string FileExtension {get; set;} public void Save() { // Save to backing store here } } Which would be the best place to check whether the values have been set correctly. In the propert setter or the Save method. Edit: What if ...

How to initialize an NSObject's subclass on iPhone?

I want to write some methods in a class so that other classes can call these methods using [instance methodName:Parameter]. If the class is a subclass of UIViewController, I can use initWithNibName to initialize it. But I want to write the methods in an NSObject's subclass, how can I initialize it? ...

How to transfer values between classes on iPhone?

I want to send a string from one class to the other: 1) In class1, I add a property to hold the string: @property (nonatomic, retain) NSString *str; 2) and a method to send back a string: -(NSString *)sendBackStr:(NSString *)strURL { NSString *str = [[NSString alloc] stringWithString:strURL]; return str; } 3) In class2, I...

How to use self class method on iPhone? (conceptual question)

I write an instance method in ClassName.m: -(void)methodName:(paraType)parameter {...} And call it using [self methodName:parameter]; A warning will pop up, but the code still runs successfully. Is this because I haven't created an instance of the class? Why the method still runs normally? And what is the correct way to call self meth...

Coding guides: How do you split up your large source files?

The project I'm working on has just hit 4200 lines in the main C# file, which is causing Intellisense to take a few seconds (sometimes up to 6 or so) to respond, during which Visual Studio locks up. I'm wondering how everyone else splits their files and whether there's a consensus. I tried to look for some guides and found Google's C++...

How to write a database class that supports parameterized queries

I'm a former classic ASP programmer and sometimes PHP programmer writing my first ASP.NET application. I'm loving the much-improved ADO.NET functions, but I'm feeling the need to write a database class. Partly I want to consolidate the code that actually interacts with the database, and partly I want to reduce what feels like repetition....

framework give me error about cannot started directly

i created web project, and added new class library for framework. This framework includes DAL. But added reference . And running no this give me no fail. runnig give me error: " A project with an Output Type of Class Library cannot be started directly In order to debug this project, add an executable project to this solution which ref...

how to declare a record inside an OCAML class

hello, I wanna declare a record inside a class as follows: class player (x, y)= object(self) type gun = {x:int; y:int; active:bool} val guns = Array.create 5 {x=0; y=0; active=false} .... but the compiler claim that this line is syntax error : type gun = {x:in .... when declared outside the class like this type : gun...

How to set up HTTP connection in a special class?

I want to create a class to handle all the HTTP connection work for other classes(in order to avoid writing codes repeatedly). I call it ConnectionCenter(subclass of NSObject) and add the following codes to it: -(void)connect:(NSString *)strURL obj:(ConnectCenter *)objConnect { NSURLRequest *theRequest=[NSURLRequest requestWithURL:...

Class Design C# Namespace Separation

I am still trying to workout separation of function and how it applies to class creation and namespace inclusion. I have a custom class SoftwareComponent which when presented to the user will most often appear as a ListItem. Is creating a ToListItem method a good idea? I worry because I have now placed a dependency in the class which wil...

Class Design - Properties or Parameters?

I am designing a class... there are crucial methods that need an object passed to them or they need to be able to "get" an object. So the question is, should you use getter/setters OR directly send the object as an argument to the method - in order for the method to work properly. Or should you set objects via the constructor if they ...

How to design a static class?

I want to create a special class for holding a lot of values like strName, strNo, intPassword...So that several other classes can modify the same value in this class. I want to use the dot syntax to call its properties like Values.strName = ...; I don't want to initialize the class everytime before I read/write its values because some o...

is placing Entity in the name of a Domain Class a good practice?

currently i am discussing if placing entity at the end of each entity is a good practice for example public class CustomerEntity:BaseEntity{} instead of public class Customer:BaseEntity{} in my career i had seen both, but how do you do it nowadays? ...

Business logic in contructor - C# / Linq to Sql

I'm extending (not sure if it's the right word here) a partial Cart class that got generated in Linq to SQL database model. The business logic is that there can be only one Cart per customer. If a customer doesn't have a cart, it should be created; if a customer has a cart, it should be returned. Here's what I'm doing: public partial...

Discussion on 'didReceiveData' method for HTTP Connection

I created an indenpendent class for HTTP connection. All the connection works fine. The problem is that I find method 'didReceiveData' will be called AFTER the method who call the connection. (method 'didReceiveData' will be called after IBAction 'accept') - (IBAction)accept:(id)sender { [self connect:url]; //labelStr = ReturnS...

What is the limit N of maximum methods you allow in your classes?

While filling in The Object Oriented Concepts Survey (To provide some academic researchers with real-life data on software design), I came upon this question: What is the limit N of maximum methods you allow in your classes? The survey then goes on asking if you refactor your classes once you reach this limit N. I've honestly never th...

Howto design for extension

There is a Checkstyle rule DesignForExtension. It says: if you have a public/protected method which is not abstract nor final nor empty it is not "designed for extension". Read the description for this rule on the Checkstyle page for the rationale. Imagine this case. I have an abstract class which defines some fields and a validate meth...