Skip to main content

New answers tagged

5 votes

Mapping complex objects to other similar complex objects

I think whether there's an appropriate pattern for this depends on how self-similar your source object ontology is. Basically, if your types are all different from each other and there are no ...
Kilian Foth's user avatar
4 votes
Accepted

Optimal way to share data between different classes

Let me restate your main issue first: you have a loosely structured Main class which has become too large over time, and now you are refactoring parts of it to classes A and B, to give the program ...
Doc Brown's user avatar
  • 210k
2 votes

Optimal way to share data between different classes

I would start by changing your perspective on the Main class. Treat this more as a composition root for your application. The Main class should be responsible for configuration and initializing ...
Greg Burghardt's user avatar
2 votes

In unit testing: How to abstract a dependency of subject under test?

How to abstract a dependency of subject under test? The short answer here is to use an interface and set your dependency as the interface type instead of the concrete class that implements said ...
Flater's user avatar
  • 52.8k
4 votes

In unit testing: How to abstract a dependency of subject under test?

Mark Seemann makes a good point, but it's important to not take these things as a universal law, and understand them with more nuance. Your GetMenuList method might be too simple for this to apply, ...
Filip Milovanović's user avatar
2 votes
Accepted

For N and NBuilder, should N be an instance variable of NBuilder, or all parameters of N be instance variables of NBuilder,finally new N() in build()?

My question is, version 1 and 2, which is the proper builder pattern? Both versions are proper implementations of the builder pattern. The builder pattern is characterized by how the client code ...
Bart van Ingen Schenau's user avatar
3 votes

How to avoid init methods when 2 objects need the reference of each other?

Another option to consider is whether MyLabel needs to exist outside of MyView at all. Sometimes it is best to simply create the object where it is needed. public class MyView { private final ...
Greg Burghardt's user avatar
-1 votes

How to avoid init methods when 2 objects need the reference of each other?

Just ignore what you heard about “code smells”. Just create a subclass of View. And give it an init method that creates a complete instance: Init the baseclass, create all the subviews, make them ...
gnasher729's user avatar
8 votes

How to avoid init methods when 2 objects need the reference of each other?

However, how to eliminate init when 2 objects need to reference to each other? For example, there are 2 UI Views: MyView and MyLabel, which MyView has a child view MyLabel, but MyLabel also needs to ...
Bart van Ingen Schenau's user avatar

Top 50 recent answers are included