All Questions
Tagged with programming-practices object-oriented
88 questions
0
votes
1
answer
370
views
How best to share common steps between services while allowing them to provide their own behaviour
I've started working on a C# codebase. There are three services which run the same set of steps of three kinds of objects, each returning IResult:
public IResult FooService(Foo foo) { ... }
public ...
2
votes
4
answers
3k
views
I wrote a class with "init" method. Should I call it from other class methods? Or leave it to the object user? (Code Design)
I have a java class with an init method. It's different from the constructor. The constructor just initializes the variables/fields. The init method connects to a database and performs some ...
-1
votes
2
answers
262
views
Do I really need TaskManager class? [duplicate]
Background:
I'm coding an app, the core idea is simple - I can choose a 'Task' (consists of name, code to perform aka Runnable, progress) through GUI, start it, stop it, start all 'Task's and stop all ...
-1
votes
1
answer
241
views
How to avoid cyclic dependency in UI application
I'm developing an UI application where I ran into an issue with a cyclic dependency. Here is the simplified code, to explain the problem.
#include <list>
class UiStyle;
UiStyle* CreateStyle();
...
0
votes
1
answer
564
views
Using for_each instead of iterators to avoid iterator invalidation
I am writing a simple custom (special purpose) container and would like to allow for iteration over each element, however, avoid using iterators due to the problem of iterator invalidation.
Instead of ...
2
votes
1
answer
118
views
Is it a good software engineering practice to store libraries as attributes of objects?
Suppose I initialize a library, say, in python object -
#filename: file_A
import file_
class A():
def __init__(self):
self.pd = file_.pd
self.np = file_.np
And suppose the ...
-1
votes
1
answer
66
views
Where is it appropriate to implement the split_array method
I am writing an implementation of a binary search tree and in doing this I need a method that splits an array in two.
I am unsure where it is appropriate to place this method. What I mean by "where ...
1
vote
2
answers
1k
views
Calling methods on objects VS. passing objects as parameters
Which is considered a generally accepted practice?
class Image {
public void decode();
};
//main
Image image;
image.decode();
vs
class ImageDecoder {
public Image run(Image image);
};
//main
Image ...
-1
votes
3
answers
175
views
How do you enforce rules for the members of a collection in a non-OOP way?
When everything seems to be a collection, how do you enforce rules for members of said collection without the use of an interface?
As far as I am aware, in languages that don't fully support OOP ...
8
votes
3
answers
7k
views
Is it good practice to make everything internal in C#?
In our solution we have a couple of projects, a project for data layer, service layer, business layer. etc.
Inside the business layer, we use models to transfer data from classes to classes. Is it ...
2
votes
2
answers
4k
views
Module with globals or Class with attributes?
Currently I'm working with a lot of modules where the original developers used global variables to control states and to exchange important information between functions, like so:
STATE_VAR = 0
def ...
1
vote
3
answers
909
views
Why shouldn't I create a class for every property?
In a particular program I had written, I noticed I had a few classes with this pattern:
class IdObject:
'''Objects with generated id properties'''
def __init__(self, id_generator):
...
-1
votes
1
answer
329
views
What is the programming paradigm when I just use functions in a file to organize my program?
I'm programming a telegram bot with Python and, for a number of reasons, there are no classes in the whole project, just several functions correlated to the the file where they are located. E.g., my ...
3
votes
5
answers
300
views
How do you force developers to define dependencies/arguments if it's bad to put the constructor function in the interface?
I just started reading more about OOP and its design patterns and is confused with this conceptual question. I am too new that I am having second thought that the proper title should be, "when is it ...
7
votes
3
answers
10k
views
Are there any drawbacks to using a nested class instead of declaring a new one?
I'm doing code review on a change my co-worker made to our Java application, and I've found something I'm not very familiar with - a nested class.
From reviewing the code, it seems like the nested ...