Timeline for Design pattern for static fields of a subclass
Current License: CC BY-SA 4.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 28, 2019 at 8:30 | comment | added | Doc Brown |
@K_7: ... however, the fluent interface offers another alternative to this: making your Optimizer objects immutable. That would mean there were no public methods like setters which can change the state of an object after its construction, and methods like withLearningRate or withNesterov will always return a new Optimizer object instead of a modified reference to the original one. But beware, immutability and inheritance don't mix well, I would be hesitant with such a design.
|
|
| Oct 28, 2019 at 7:33 | comment | added | Doc Brown |
@K_7: when users can instantiate their own optimizer objects, there is no need for having a static instance Optimizers.GD. I would heavily recommend to remove this, this is nothing but a "global variable", and your issues are just the usual drawbacks of global variables.
|
|
| Oct 28, 2019 at 7:31 | history | edited | Doc Brown | CC BY-SA 4.0 |
added 81 characters in body
|
| Oct 27, 2019 at 23:20 | comment | added | Kartik Chugh |
My only outstanding question is how to prevent users from calling the setters on Optimizers.GD? ie. new Gd().withNesterov is fine, but GD.withNesterov() isn't. I'm thinking I'll make a second constructor that takes a boolean, and as long as this boolean is true, then no state changes can occur within the Optimizer. And then define GD as the following public static final Gd GD = new Gd(true);
|
|
| Oct 27, 2019 at 22:59 | comment | added | Kartik Chugh | Resolved my issues by 1. implementing the fluent-inheritance pattern 2. realizing that users should instantiate a new instance of the optimizer if they want to change some of the default parameters | |
| Oct 27, 2019 at 22:59 | vote | accept | Kartik Chugh | ||
| Oct 27, 2019 at 20:16 | history | edited | Doc Brown | CC BY-SA 4.0 |
added 17 characters in body
|
| Oct 27, 2019 at 20:10 | history | edited | Doc Brown | CC BY-SA 4.0 |
added 17 characters in body
|
| Oct 27, 2019 at 19:46 | comment | added | Kartik Chugh | - in the current design, this would not be possible, since there would always be only one OptimizerGD object with either nesterov set to true or to false Yikes! Didn't realize this | |
| Oct 27, 2019 at 19:18 | comment | added | Jörg W Mittag | Good old F-bounded polymorphism. Is there any problem, you can't solve? :-D | |
| Oct 27, 2019 at 19:00 | history | answered | Doc Brown | CC BY-SA 4.0 |