All Questions
Tagged with programming-practices object-oriented
88 questions
3
votes
11
answers
2k
views
OO Software Architecture - base class that everything inherits from. Bad/good idea?
I am reviewing a proposed OO software architecture that looks like this:
Base
Foo
Something
Bar
SomethingElse
Where Base is a static class.
My immediate thought was that every object in any class ...
25
votes
2
answers
18k
views
Exceptions in DDD
I'm learning DDD and I'm thinking about throwing exceptions in certain situations. I understand that an object can not enter to a bad state so here the exceptions are fine, but in many examples ...
4
votes
3
answers
1k
views
Turning structural code into object oriented code
This is a bit experimentation from my part because I had written a lot of procedural code back in my school days hence I have trouble in thinking in OOP way i.e. to find proper classes and ...
1
vote
1
answer
907
views
Can a class factory also save the object to a database?
How can a factory also save the object in the database?
I want to create an object that consists of other objects.
Pseudocode:
firstObject = db.get....;
secondObject = db.get....;
expectedObject = ...
4
votes
1
answer
6k
views
Where should variables be declared
Considering I have a for loop in a method of a class. Should the incremented variable be declared as member of the class, or should it be declared in the method it uses it(or even in the for loop, ...
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 ...
276
votes
14
answers
125k
views
Should we avoid object creation in Java?
I was told by a colleague that in Java object creation is the most expensive operation you could perform. So I can only conclude to create as few objects as possible.
This seems somewhat to defeat ...
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 ...
2
votes
1
answer
274
views
Is it OK to deprecate methods that need to be public due to the packaging model but are not to be used outside the codebase in Java?
I am currently working on a semi-large project that has several packages. There are 3 main packages, a "client" package, a "server" package and a "common" package. There are two jars, one for the ...
13
votes
3
answers
14k
views
Should main method be only consists of object creations and method calls?
A friend of mine told me that, the best practice is class containing main method should be named Main and only contains main method. Also main method should only parse inputs, create other objects and ...
-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 ...
36
votes
13
answers
5k
views
Why should a class be anything other than "abstract" or "final/sealed"?
After 10+ years of java/c# programming, I find myself creating either:
abstract classes: contract not meant to be instantiated as-is.
final/sealed classes: implementation not meant to serve as base ...
9
votes
7
answers
4k
views
what can go wrong in context of functional programming if my object is mutable?
I can see the benefits of mutable vs immutable objects like immutable objects take away lot of hard to troubleshoot issues in multi threaded programming due to shared and writeable state. On the ...
2
votes
5
answers
1k
views
What should a constructor contain?
What should a constructor contain?
In both cases, all three arguments are needed for the class to work.
Which approach is better and why?
1)
class Language {
LanguageRepository ...