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

learn more… | top users | synonyms

9
votes
5answers
3k views

Interface and Inheritance: Best of both worlds?

I 'discovered' interfaces and I started to love them. The beauty of an interface is that it is a contract, and any object that fulfills that contract can be used wherever that interface is required. ...
5
votes
4answers
275 views

Best way to handle class relationship

Take a User class and the idea that a User is to be profiled. I see four ways to handle this: Write the code for the profile into the User class. I am dismissing this right away. Create a Profile ...
6
votes
10answers
525 views

Teaching Classes and Objects [closed]

I'm trying to teach how an object is just an instance of a class to a buddy of mine. However, he doesn't seem to understand it so well. I've heard a ton of the examples (blueprint to a house, etc.) ...
6
votes
6answers
1k views

Organizing Class Members in Regards to Access Modifier

If we look at typical implementation of a Class, we usually see the private members defined at the beginning and public( mostly functions and Accessors) defined towards the bottom. Now, is this a ...
3
votes
3answers
396 views

Is partial classes modern Subject-Oriented programming?

Important discussion follows: C# and other language have made partial classes more popular. But isn't this really a tool that have reinvented the subject-orientated programming wheel? What do you ...
3
votes
3answers
282 views

Proper use of classes

I'm writing a class that draws a very complex image, with multiple parts. I also plan on adding to the class to add more functionality. Would it be right to make a function for each part, even if that ...
5
votes
2answers
576 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 ...
10
votes
2answers
303 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
141 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: ...
9
votes
6answers
2k 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
269 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
169 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
962 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
724 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
427 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
224 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
124 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
439 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 ...
8
votes
4answers
4k 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 ...
15
votes
9answers
7k 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
732 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 ...
10
votes
6answers
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
3k 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 ...
13
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: ...