"Il y a peu de choses qui me soient impossibles..."
Ron McLeod wrote:Couldn't you make a decision based on the type of the other hull?
"Il y a peu de choses qui me soient impossibles..."
"Il y a peu de choses qui me soient impossibles..."
Dave Tolls wrote:The issue here is that you have classes that implement Hull that are tightly coupled.
The SquareHull class has to know of the existence of other Hull types in order to do its job, in this case the RoundHull.
To me that says the class is more a property and might be better represented as (say) an enum, in which you can then apply the relevant logic.
"Il y a peu de choses qui me soient impossibles..."
Possible Hull Type Pairs | First Hull Type | |||
Circ | Rect | Poly | ||
Second Hull Type | Circ | Circ/Circ | Rect/Circ | Poly/Circ |
Rect | Circ/Rect | Rect/Rect | Poly/Rect | |
Poly | Circ/Poly | Rect/Poly | Poly/Poly |
"Il y a peu de choses qui me soient impossibles..."
I wrote:When I tried it just now, it became apparent that it was going to be a big PITA
"Il y a peu de choses qui me soient impossibles..."
Stevens Miller wrote:I have come up with this horror:
...the overlaps(Hull, Hull) method in the HullShapes enum is a gawdawful ugly mess.
Is this approach viable? Is it even defensible?
in a tweet, Sandi Metz wrote:Don't write code that guesses the future, arrange code so you can adapt to the future when it arrives.
https://twitter.com/sandimetz/status/441241600077725697
There are three kinds of actuaries: those who can count, and those who can't.
Junilu Lacar wrote:What's wrong with the general approach that Tobias suggested?
"Il y a peu de choses qui me soient impossibles..."
Tobias Bachert wrote:Assuming that your methods may not be able to simply return true or false -> if you have to perform some kind of calculations to determine the result:
You could replace the huge switch block with a map containing bi-predicates which should scale better when the count of options increases
"Il y a peu de choses qui me soient impossibles..."
Junilu Lacar wrote:And you still won't have to use instanceof with that suggestion I made. You'd still use the enum HullShape as the Hull attribute that you check to see if a particular Hull can be handled by a HullOverlapChecker.
"Il y a peu de choses qui me soient impossibles..."
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:How accurate should these overlap calculations be? I was thinking of each Hull being able to come up with a set of axes aligned rectangles that together approach its area, and that would greatly simplify overlap calculations and better: you would be independent of any particular Hull for the calculation.
"Il y a peu de choses qui me soient impossibles..."
Junilu Lacar wrote:I'd be interested in how Tobias' suggestion works out for you.
A couple of smells I'd be wary about: the static methods and what looks to be a manually set up dispatching system.
I'd try with a few pairs of Hulls and HullShapes first, then see how difficult it would be to add more Hull types.
I haven't tried my suggestion but I still think the problem matches the context suited for applying the Chain of Responsibility/Command pattern.
"Il y a peu de choses qui me soient impossibles..."
Junilu Lacar wrote:I would put understanding the problem and finding a solution that I understand before any considerations around performance. It's easier for me to find ways to make something faster when I fully understand how it works. Conversely, I'd have a hard time figuring out how to make something that I don't fully understand work faster.
I know graphics programs take performance considerations to a whole 'nother level but I would guess that a few dozen links in a chain of responsibility won't register anywhere near the speed limit for any modern laptop.
Nevertheless, I'd still be really interested to see how a full implementation of Tobias' design would work out. I'll keep an eye out for an update from you.
"Il y a peu de choses qui me soient impossibles..."
"Il y a peu de choses qui me soient impossibles..."
Stevens Miller wrote:At Line 17, I replaced "BiPredicate<T, U>" with BiPredicate<Hull, Hull>," which allowed me to drop the cast that would otherwise have appeared at Line 20
Tobias Bachert wrote:The main-problem with this change is, that you can no longer use the specific hull-types in your method/lambda. Your CircCirc predicate can no longer access methods of a CircHull as your arguments are now of the Hull-supertype instead of the specific subtype
"Il y a peu de choses qui me soient impossibles..."
Tobias Bachert wrote:Line 7) You can replace the lambdas with static methods as shown above, is a bit shorter and in my opinion better readable (and avoids the creation of additional classes).
"Il y a peu de choses qui me soient impossibles..."
"Il y a peu de choses qui me soient impossibles..."
Dave Tolls wrote:Out of curiosity is the logic for CH x RH and RH x CH the same?
"Il y a peu de choses qui me soient impossibles..."
Are you here to take over the surface world? Because this tiny ad will stop you!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|