Questions tagged [class-design]
General guidelines on how to design classes with best known industry practices.
451
questions
6
votes
6
answers
1k
views
Is a callback function with `this` as an argument a bad practice?
I have a class that has a callback function that gets triggered on some event. The user of the class instance is expected to do stuff on the instance itself, inside this callback function. So I am ...
3
votes
1
answer
221
views
Object-oriented programming design with relational database tables
I want to understand what is considered best-practice to better align with OOP when handling relational databases. I cannot find any online examples where classes and a more maintainable/re-usable ...
-2
votes
1
answer
114
views
Defining functions inside vs outside a class
Say I have a class with a function do_thing that is comprised of multiple steps, which themselves segregate into functions (first_process and second_process). At what point would this be considered ...
0
votes
1
answer
87
views
DAL class structure for storing and organizing SQL using Dapper?
I'm creating a web application with Asp.Net Core MVC, and I've replaced Entity Framework with a custom data store. I've decided to use Dapper, but have never used it prior to this project. So I'm ...
0
votes
1
answer
124
views
API design question: Should a builder perform expensive validation when building?
I'm working on a library of C++ wrappers/bindings, for another, C-ish, API.
The C'ish API has a "launch" function, which, among other things, takes a launch configuration structure (well, ...
0
votes
2
answers
199
views
Possible violation of LSP when adhering to ISP?
Recently I read about ISP and wanted to implement it into my project. While implementing my design I think I found a flaw which violates LSP but I'm not sure.
Given I have a game project, in which ...
4
votes
1
answer
164
views
Is there a proper term for a "closed class hierarchy?"
What I mean by "closed class hierarchy" is a set of known base/derived classes used only for an implementation of something with no public API, i.e., the classes are not meant to be derived ...
0
votes
1
answer
117
views
Functional interfaces or decorator-like implementations [closed]
Consider Chess as an example. Say, we have a lot of domain objects that are alike, in this case chess pieces. I have two proposes to implementing the behaviour of chess pieces. Both uses the following ...
1
vote
2
answers
404
views
Splitting up large SQLAlchemy model
Anybody have advice on splitting up a large SQLAlchemy model into smaller parts? I have a ~2000 line model called Article that is becoming difficult to manage. We often have to scroll and scroll to ...
2
votes
2
answers
1k
views
Why access the attributes of a Python class by reference?
Attribute references and instantiation
In this link, that is part of the official Python documentation, I have found the following information:
Class objects support two kinds of operations: ...
0
votes
2
answers
198
views
For non-container classes, are "better naming" and "ready for commented codes" good reasons not to declare the most abstract type?
According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I know I should declare the most abstract type possible, but the question is about template class ...
2
votes
3
answers
174
views
Class design using Open and Close Methods
As the title says, Im thinking if it's a good practise to have classes that have Open and Close methods in the sense that they can be reused without a new instance being created again.
Also, if I want ...
1
vote
2
answers
245
views
Is "declaring most abstract type" suffers from the same problem as "primitive obsession"?
According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), when creating objects, I should declare the most abstract type, eg : Map hashMap=new HashMap(). ...
0
votes
0
answers
45
views
Class Composition For A List With Multiple Types
I have some classes like so
class User{
Preferences
List<Participants>
BlueFontParticipants
PropertyThatComputesFromAListOfParticipants<Participants>
}
class Preferences{
...
0
votes
6
answers
1k
views
Is it best practice for each call to a SQL Server to be in its own class, even when using dependency injection?
I often see/write classes that contain every part of the application where the application will talk to a SQL server. For example, you may have a class like this
public class Data
{
private Func&...