Skip to main content

All Questions

3votes
11answers
2kviews

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 ...
25votes
2answers
18kviews

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 ...
4votes
3answers
1kviews

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 ...
1vote
1answer
907views

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 = ...
4votes
1answer
6kviews

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, ...
2votes
2answers
4kviews

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 ...
276votes
14answers
125kviews

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 ...
0votes
1answer
368views

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 ...
2votes
4answers
3kviews

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 ...
2votes
1answer
274views

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 ...
13votes
3answers
14kviews

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 ...
-1votes
2answers
262views

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 ...
36votes
13answers
5kviews

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 ...
9votes
7answers
4kviews

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 ...
2votes
5answers
1kviews

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 ...

153050per page
close