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

learn more… | top users | synonyms

5
votes
3answers
237 views

How to name an subclass that add a minor, detailed thing?

What is the most concise (yet descriptive) way of naming a subclass that only add a specific minor thing to the parent? I encountered this case a lot in WPF, where sometime I have to add a small ...
11
votes
4answers
6k views

C++ - Constructor or Initialize Method to Startup [duplicate]

Possible Duplicate: Avoid having an initialization method I want to determine when to do non-trivial initialization of a class. I see two times to do initialization: constructor and other ...
2
votes
2answers
271 views

Strategies for invoking subclass methods on generic objects [duplicate]

Possible Duplicate: Alternatives to type casting in your domain I've run into this issue in a number of places and have solved it a bunch of different ways but looking for other solutions ...
2
votes
2answers
3k views

DB Object passing between classes singleton, static or other?

So I'm designing a reporting system at work it's my first project written OOP and I'm stuck on the design choice for the DB class. Obviously I only want to create one instance of the DB class ...
14
votes
9answers
2k views

Isn't class scope purely for organization? [duplicate]

Isn't scope just a way to organize classes, preventing outside code from accessing certain things you don't want accessed? More specifically, is there any functional gain to having public, protected, ...
3
votes
1answer
119 views

Naming a class that processes orders

I'm in the midst of refactoring a project. I've recently read Clean Code, and want to heed some of the advice within, with particular interest in Single Responsibility Principle (SRP). Currently, ...
0
votes
3answers
151 views

Best practice to propagate preferences of application

What is your approach with propagation to all classes/windows of preferences/settings of your application? Do you share the preference_manager class to all classes/windows who need it or you make ...
49
votes
12answers
4k views

Is it bad practice to pass instances through several layers?

In my program design, I often come to the point where I have to pass object instances through several classes. For example, if I have a controller that loads an audio file, and then passes it to a ...
5
votes
4answers
631 views

Method flags as arguments or as member variables?

I think the title "Method flags as arguments or as member variables?" may be suboptimal, but as I'm missing any better terminology atm., here goes: I'm currently trying to get my head around the ...
6
votes
3answers
2k views

Data classes: getters and setters or different method design

I've been trying to design an interface for a data class I'm writing. This class stores styles for characters, for example whether the character is bold, italic or underlined. But also the font-size ...
0
votes
2answers
957 views

A sample Memento pattern: Is it correct?

Following this query on memento pattern, I have tried to put my understanding to test. Memento pattern stands for three things: Saving state of the "memento" object for its successful ...
11
votes
4answers
2k views

Object Oriented Programming: getters/setters or logical names

I'm currently thinking about an interface to a class I'm writing. This class contains styles for a character, for example whether the character is bold, italic, underlined, etc. I've been debating ...
1
vote
1answer
108 views

How to represent association in programs [closed]

Could someone help me in implementing association in cpp. I am trying to implement a dice game where I have two classes a diegame and a dice.
3
votes
6answers
4k views

How to properly design classes for a big project?

If we need to represent classes in a class diagram for a big project that is not completely designed yet, and the classes have to be actual tables in a database, how would we predict and design the ...
1
vote
4answers
1k views

When using Hibernate can we forget about Database Design?

We started (just me and my friend) working on a website. As a part design phase we have finished the drawing a Site Map, decided on the content in each of the web page and the navigation. As we want ...
1
vote
1answer
192 views

The design of a generic data synchronizer, or, an [object] that does [actions] with the aid of [helpers]

I'd like to create a generic data-source "synchronizer," where data-source "types" may include MySQL databases, Google Spreadsheets documents, CSV files, among others. I've been trying to figure out ...
1
vote
2answers
136 views

Class design, One class in two sources

Is it possible define methods from the same class in different "CPP" files? I have header file "myClass.h" with: class myClass { public: // methods for counting ... // methods for ...
5
votes
3answers
4k views

Can a class be inside another class?

Here's an excerpt from "The C++ Programming Language" template<classT> class List { // optimal public: class Link { /* ... */ }; List (); // initially empty void put(T *); // put before current ...
2
votes
6answers
2k views

Class Design — Multiple Calls from One Method or One Call from Multiple Methods?

I've been working on some code recently that interfaces with a CMS we use and it's presented me with a question on class design that I think is applicable in a number of situations. Essentially, what ...
3
votes
3answers
163 views

Class fields/variables. Keep single reference point at class level or pass to individual methods?

Often I see a class where a value is injected into a method or even a constructor. That value is then used by several methods within that class and a reference is simply passed through to each method ...
2
votes
0answers
415 views

Provide an OnChange event for an internal property which is controlled externally?

For fun and by request I am updating this ImageGrid component, a kind of listbox for images that has a FileNames property of type TStrings. For ease of writing, I have been misusing its ...
4
votes
3answers
161 views

What class structure allows for a base class and mix/match of subclasses? (Similar to Users w/ roles)

I have a set of base characteristics, and then a number of sub-types. Each instance must be one of the sub-types, but can be multiple sub-types at once. The sub-types of each thing can change. In ...
9
votes
3answers
1k views

Base classes as factories?

I was writing some code over the weekend and I found myself wanting to write a factory as a static method in a base class. My question is simply to know if this is a c# idomatic approach? My sense ...
1
vote
1answer
2k views

Encapsulating a class within another class to hide its exposed properties and details

I have essentially a data model class that represents an XML data structure that we use to model our system. The model class is in a shared project that is used by a number of different solutions in ...
6
votes
3answers
169 views

Grouping conceptual algorithms into one class or associate with their object models

If I have a number of classes, lets say a variety of buildings of some sort. Each of these buildings have various properties and do some stuff etc Now there is a set of operations I need to do on ...
3
votes
2answers
241 views

Designing class methods: self contained or explicit calls?

I'm probably butchering the terms, if someone knows the appropriate terms - that'd be great. But my question is: should I design my classes so that their methods' parameters be accessible from the ...
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
272 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
508 views

Teaching Classes and Objects

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
865 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
373 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
277 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
522 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
298 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
137 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: ...
8
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
251 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
166 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
781 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
636 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
375 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
204 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
121 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
423 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 ...
13
votes
9answers
6k 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
715 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 ...