General guidelines on how to design classes with best known industry practices.
0
votes
1answer
149 views
How can my code structure be improved? [closed]
I am looking for advice on the neatest way to structure my code.
class Password
{
private string cipher;
Password(string cipher)
{
this.cipher = cipher;
}
public string ...
3
votes
3answers
320 views
Why is it so difficult to know where to use interfaces,generics in program design?
I am attempting to learn c# from the head first series, in addition i also consult other books such as Pro C# by Andrew Tolson.
Now the thing is that i perfectly understand the interface,generics ...
1
vote
1answer
77 views
Designing a list class with filtering and sorting
The app I'm developing needs to display lists of items. Simple enough, but there are a number of things which can change based on user input:
Items can be added to/removed from the list.
The items ...
17
votes
2answers
877 views
Is it a good idea to provide different function signatures that do the same thing?
Here is a C++ class that gets constructed with three values.
class Foo{
//Constructor
Foo(std::string, int, char);
private:
std::string foo;
char bar;
int baz;
};
All of ...
3
votes
3answers
205 views
Architecting persistence (and other internal systems). Interfaces, composition, pure inheritance or centralization?
Suppose that you need to implement persistence, I think that you're generally limited to four options (correct me if I'm wrong, please)
Each persistant class:
Should implement an interface ...
8
votes
7answers
679 views
Is it appropriate for a class to only be a collection of information with no logic?
Say I have a class Person that has instance variables age, weight, and height, and another class Fruit that has instance variables sugarContent and texture. The Person class has no methods save ...
0
votes
3answers
219 views
UML - Class Diagrams Order -> Products
I have a class diagram that is like this:
< Order > (1) CAN HAVE (M) < products >
But therefore Order has the following:
Order_Id
Customer_Id
Order_date_day
Order_date_month
...
0
votes
1answer
161 views
Class Design and Structure Online Web Store
I hope I have asked this in the right forum.
Basically, we're designing an Online Store and I am designing the class structure for ordering a product and want some clarification on what I have so ...
3
votes
3answers
163 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 ...
6
votes
4answers
399 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
99 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 ...
3
votes
2answers
311 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 ...
17
votes
9answers
954 views
Isn't class scope purely for organization?
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
89 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
119 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 ...
43
votes
12answers
3k 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
297 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
720 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
1answer
402 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
724 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 ...
0
votes
1answer
77 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
1k 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 ...
0
votes
4answers
454 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 ...
0
votes
1answer
89 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
124 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
805 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
843 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
122 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
156 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
129 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 ...
8
votes
3answers
644 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
689 views
Encapsulating a class within another class to hide it's 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
108 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
166 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 ...
7
votes
5answers
672 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
237 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
403 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
416 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 ...
0
votes
3answers
295 views
Review my class hierarchy [closed]
I have created a class hierarchy for an inventory system for a book/magazine. Here's the picture:
Will it do? I know there's no magazine class yet but I was wondering if anyone could suggest a ...
2
votes
3answers
282 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
265 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
257 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
796 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
279 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
115 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: ...
5
votes
5answers
530 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
192 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
148 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
359 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
398 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. ...