Skip to main content
28 events
when toggle format what by license comment
Apr 9, 2022 at 19:01 audit First questions
Apr 9, 2022 at 19:01
Apr 8, 2022 at 15:40 answer added Gabe Sechan timeline score: 0
Apr 6, 2022 at 14:37 comment added Filip Milovanović That is, it has well-defined high-level behavior, with a well-defined interface that facilitates it, and the whole encapsulation thing is in service of that. You can build even higher level logic on top of that - which is what you want. Otherwise, the object appears super decoupled, but you can't do much with it except treat it as an entry point and make the method call at the appropriate time. Passing in data extrinsic to the core responsibility of the object is often more flexible, and the object gets to define the exact interface/protocol for how that data is passed in. 2/2
Apr 6, 2022 at 14:37 comment added Filip Milovanović One of the major sources of confusion when it comes to software design stems from the tendency to think of encapsulated objects as of "fully self contained magic black boxes" where, if the method names were scrambled, you basically could not tell what the object does, what it's for. But, actually, a with a well encapsulated object, even if the method names were scrambled, you should in principle be able to eventually infer what it does (by making different calls and examining outputs, or invocations of dependencies) in terms of high-level logic, without knowing how it achieves it. 1/2
Apr 6, 2022 at 8:23 comment added Tvde1 In real life, who verifies a customer's age? Is it the customer itself or the bartender?
Apr 6, 2022 at 6:03 history protected gnat
Apr 6, 2022 at 3:47 answer added Jessica timeline score: 0
Apr 6, 2022 at 2:59 answer added Cloudy timeline score: 6
Apr 6, 2022 at 0:53 answer added jwezorek timeline score: 0
Apr 5, 2022 at 17:33 answer added Ewan timeline score: 19
Apr 5, 2022 at 15:54 answer added Urausgeruhtkin timeline score: 15
Apr 5, 2022 at 15:00 history tweeted twitter.com/StackSoftEng/status/1511358004578459651
Apr 5, 2022 at 14:57 comment added abuzittin gillifirca What does the user object do? The answer depends on that.
Apr 5, 2022 at 14:26 comment added GACy20 Option 3, your class can receive a "DateProvider" as argument in the constructor and call that instead of using new Date(), for testing you can then pass a mock/stub provider.
Apr 5, 2022 at 14:21 comment added Pablo H A little change might dissipate the problem: call your method hasMinimumLegalAgeOn(when: Date). It's obvious it takes a date. :-)
Apr 5, 2022 at 14:20 comment added Josh Part Approach 3: get the current date from configuration source (server, file, database)...?
Apr 5, 2022 at 14:12 answer added Willa timeline score: 8
Apr 5, 2022 at 13:39 comment added Thiago Dias @MattTimmermans I definitely can see another object being responsible for telling when a user is legal in another scenario, but to add getBirthDate() would just leak encapsulation, "who" should know that the legal age is 21 or any other number? sure, it depends on the context, but...
Apr 5, 2022 at 13:27 comment added Matt Timmermans The user is not the entity that decides what minimum legal age is. Probably best just to replace it with getBirthDate
Apr 5, 2022 at 12:26 comment added Joop Eggen @gavioto20 I was aware of that. But I thought the abstraction "clock" far better than "date" (date time). Because a clock can run false. Hence the comment.
Apr 5, 2022 at 12:17 history became hot network question
Apr 5, 2022 at 10:59 comment added gavioto I think the question is not relative to Java but for OOP. So there should be a generic solution or approach for the problem. @JoopEggen
Apr 5, 2022 at 10:53 comment added Joop Eggen Java has a Clock you can pass, so unit tests can pass their own fixed one. Better abstraction than a fake now.
Apr 5, 2022 at 8:39 answer added gnasher729 timeline score: 1
Apr 5, 2022 at 7:35 answer added Doc Brown timeline score: 24
Apr 5, 2022 at 7:16 answer added Flater timeline score: 18
Apr 5, 2022 at 6:25 answer added JacquesB timeline score: 56
Apr 5, 2022 at 3:27 history asked Thiago Dias CC BY-SA 4.0