General guidelines on how to design classes with best known industry practices.

learn more… | top users | synonyms

5
votes
2answers
464 views

Should exceptions of a subclass extend the superclass exceptions or my own namespace?

Our library extends another (third-party) library. When we create a child class in our library, and want to throw exceptions, should those exceptions extend the exceptions from the parent class or ...
5
votes
7answers
2k views

Where should I put my utility methods?

I am very new to Visual Studio and C# and am wondering how best to create a repository of sorts for utility methods. For instance, we need a method that returns the current fiscal year and other ...
9
votes
2answers
295 views

is it a reasonable practice to extend a class just to reuse a single function?

I am developing a range of post filters for a wordpress site, and I have built the first 4 with a single class. The final two are different enough in scope to only share a single function (the ...
0
votes
2answers
135 views

Is hooking Data access method on wrong object detrimental for a developer

In a simple application I am creating there are Admin and users where admin can create users. Right now I am creating Classes that encapsulate database CRUD calls with methods. For example: ...
7
votes
6answers
1k views

Prefer class members or passing arguments between internal methods?

Suppose within the private portion of a class there is a value which is utilized by multiple private methods. Do people prefer having this defined as a member variable for the class or passing it as ...
3
votes
5answers
237 views

How to decide which classes are necessary for the system

I know design principles and design patterns in theory. But it's embarrassing to realize that it's not clear when applying it in practice. For example, let's think about simple tic tac toe console ...
5
votes
1answer
165 views

How to design an algorithm-heavy and object-light application

Other than vertices, edges, faces and meshes, my geometry processing project/application has only about half a dozen other entities such as curves on surfaces. However the majority of my code is ...
3
votes
3answers
598 views

What is a Munger

I am reading the source code of ObjectListView and there is a Munger class. What is Munger? Does Munger mean anything general in programming jargon? Afaik, the Munger in the source code wraps the ...
2
votes
3answers
594 views

GUI: Setting options in two different places and having them stay in sync?

Programming in Windows with Visual Studio 2010 C++ and MFC. My question is about how best to store, update, and pass around program settings or options. I have a simple main GUI window/frame/dialog. ...
3
votes
3answers
325 views

Design: Method that loads data from one of two file formats?

Say I have a class Person: class Person { string FullName; int Age; } And I need to load a list of Person's from a plain text file. The text file could be in one of two formats. I want a ...
3
votes
1answer
192 views

How to organize a set of syntax highlighting classes?

I am creating a set of syntax highlighters for an application. The languages include: HTML (specifically HTML5) JavaScript PHP CSS (specifically CSS3) The problem lies in the way the classes need ...
11
votes
3answers
3k views

Abstract Base Class with Interfaces as Behaviors?

I need to design a class hierarchy for my C# project. Basically, class' functionalities are similar to WinForms classes so let's take WinForms toolkit as an example. (However, I can't use WinForms or ...
1
vote
1answer
116 views

Using “public” vars or attributes in class calls, functional approach

I was always wondering about two things I tend to do in my little projects. Sometimes I will have this design: class FooClass ... self.foo = "it's a bar" self._do_some_stuff(self) ...
2
votes
2answers
407 views

How To Organize Factories in a .Net Project?

I'm just beginning to grasp the concept of factories, and want to use them in my next project (I'm using dependency injection, so using factories will make object instantiation easier). Some basic ...
6
votes
4answers
3k views

Use Dependency Injection For Data Objects?

I'm just learning about dependency injection, and am stuck on something. Dependency Injection recommends sending dependent classes through the constructor, but I'm wondering if this is necessary for ...
11
votes
9answers
4k views

When should you use a private/inner class?

To clarify, what I'm asking about is public class A{ private/*or public*/ B b; } vs. public class A{ private/*or public*/ class B{ .... } } I can definitely think of some ...
10
votes
2answers
696 views

Design: Object method vs separate class's method which takes Object as parameter?

For example, is it better to do: Pdf pdf = new Pdf(); pdf.Print(); or: Pdf pdf = new Pdf(); PdfPrinter printer = new PdfPrinter(); printer.Print(pdf); Another example: Country m = new ...
7
votes
7answers
2k views

At what point do immutable classes become a burden?

When designing classes to hold your data model I've read it can be useful to create immutable objects but at what point does the burden of constructor parameter lists and deep copies become too much ...
9
votes
5answers
1k views

How do we know to favour composition over generalisation is always the right choice?

Whether an object physically exists or not, we can choose to model it in different ways. We could arbitarily use generalisation or composition in many cases. However, the GoF principle of "favour ...
7
votes
5answers
2k views

Can You Have “Empty” Abstract/Classes?

Of course you can, I'm just wondering if it's rational to design in such a way. I'm making a breakout clone and was doing some class design. I wanted to use inheritance, even though I don't have to, ...
2
votes
2answers
1k views

What is the best way to work with DAL and BLL?

I'm currently refactoring my DLL and BLL and I need some advice on what is the best way to work with DAL and BLL. My current solution is like this: // DAL class only consists of SQL queries and ...
12
votes
4answers
2k views

Is It “Wrong”/Bad Design To Put A Thread/Background Worker In A Class?

I have a class that will read from Excel (C# and .Net 4) and in that class I have a background worker that will load the data from Excel while the UI can remain responsive. My question is as follows: ...