All Questions
Tagged with programming-practices object-oriented-design
38 questions
-1
votes
1
answer
167
views
Help in understanding if my design getting complicated [closed]
I have 3 classes
class Backup
end
class Database
end
Class App
end
The backup database has a reference to Database and App, like
class Backup
def getDatabase
Database.create
end
def ...
2
votes
3
answers
235
views
Correctness of an implementation beyond the methods signature contract of an interface
Is there a programming principle/guideline that tackles the correctness of a implementation beyond the methods signature contract of an interface?
Let's say we have a repository interface with two ...
-1
votes
1
answer
107
views
How can I prevent an object from being re-sanitized everytime it is passed as input to a function?
Suppose that I have a class named CharStream
Additionally, there are a large number of functions which convert their function input into a CharStream
def funky_the_function(_input):
input = ...
3
votes
4
answers
780
views
Is it a bad practice to have an interface method to tell whether it can handle an object?
interface Resolver {
boolean canResolve(SomeInput input);
SomeOutput resolve(SomeInput input);
}
public static void main(String[] args) {
List<Resolver> resolvers = ...;
...
4
votes
3
answers
1k
views
Passing object or using the field
I would like to know what is a more appropriate way to code in Java. Is it generally better to pass entire objects in the method's parameters or just using the fields from the class?
Using the field:
...
-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();
...
-1
votes
3
answers
226
views
Difference between update a property and fire an event
It seems to me that update a property is always an 'event' and that all you can do with an event handler can be done in the property let/set routine.
And, in my limited experience, I never needed to ...
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 ...
0
votes
2
answers
2k
views
Should I use a class with only static members to encapsulate my program?
So I'm writing a network simulator in C++ as part of a university project. Right now, I have a class structure that looks something like:
//includes type aliases
#include "GlobalTypes.h"
//main body ...
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 ...
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
1
answer
618
views
Should the function that operates on the object return it?
Should the function that operates on the object return it?
Shortened example:
class Example1
{
public function method($a, $b)
{
$result = new Result($a, $b);
$this->...
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 ...
-6
votes
1
answer
189
views
Finding object relationships [closed]
Description
Its a follow up question of writing use cases.
Taking from nouns defined in my user story and requirement I found the following candidates to be classes:
User
Question
Session
Attempt/...
4
votes
4
answers
539
views
Is it better to generate a large list during the constructor or when it's accessed?
I've got a class member function that generates a large list and puts it into a private member variable so it can be accessed through a getter. The generation of this list is a rather intensive ...