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
3 votes

If class B extends A, can we say that B depends on A?

While you probably won’t convince your coworkers and not sure you should try (using non-standard terminology isn’t likely to work in your favor with others) I would argue this is a dependency every ...
bob's user avatar
  • 149
-2 votes

If class B extends A, can we say that B depends on A?

In semantical English, you are correct. However, a "dependency" has a very specific meaning in the software development world, and inheritance is not an example of such a dependency. A ...
Flater's user avatar
  • 52.8k
3 votes

If class B extends A, can we say that B depends on A?

Does B extends A imply that B depends on A? Believe it or not, this is an implementation detail of the language. I can prove it. Ever heard of single data inheritance? Lets say we have a record of two ...
candied_orange's user avatar
7 votes
Accepted

If class B extends A, can we say that B depends on A?

You are both right depending on your interpretation of "depends"... pun not intended. If you interpret "depend" to mean "class B cannot exist without class A" then you ...
Greg Burghardt's user avatar
0 votes

What is the better way to escape from too many if/else-if from the following code snippet?

The switch statement with nine cases is simple, obvious, doesn’t require any extra code, and is easily extended. Note how all the answers actually avoided writing nine cases down. So they are more ...
gnasher729's user avatar
1 vote

Clarify the Open/Closed Principle

Your understanding is correct. In the original version of the principle (coined by OOP pioneer Bertrand Meyer), you don't modify existing ("published") code except for bug-fixes. All changes ...
JacquesB's user avatar
  • 59.9k
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