Often when I try to customize Fuse core functionality I experience that the access modifiers is too strict for me to do what I want in an easy way, and I end up having to copy and paste a lot of code.
- I want to create a version of
SwipeNavigate with more tolerance, and want to change this:
SwipeGestureHelper _horizontalGesture = new SwipeGestureHelper(10.0f,
new DegreeSpan( 75.0f, 105.0f),
new DegreeSpan(-75.0f, -105.0f));
SwipeGestureHelper _verticalGesture = new SwipeGestureHelper(10.0f,
new DegreeSpan(-15.0f, 15.0f),
new DegreeSpan(-165.0f, -180.0f),
new DegreeSpan( 165.0f, 180.0f));
- I want to change HttpImageSource to JpegHttpImageSource.
- I want to create a CachedHttpImageSource that saves the image to a file.
These are just some examples from this weekend from when I end up copy-pasting instead of subclassing or configuring core components when I want a slightly diffrent behaviour.
SwipeNavigate is not sealed, so I don’t see the problem there?
HttpImageSource, we could consider making that non-sealed.
The reason we seal classes is to avoid making more breaking changes than neccessary in the future. Making a class non-sealed is a much bigger future compatiblity promise than providing sealed classes. Once something is non-sealed, the
protected API is in practice publicly visible, and we cannot change it anymore without breaking backwards compatibility.
SwipeNavigate is not sealed, but if I want to change the part that I showed in my original post I need to:
Copy OnRooted, OnUnrooted, OnPointerPressed, OnPointerMoved, OnPointerReleased, Navigation, _currentNavigation and all places that uses _currentNavigation, _horizontalGesture, create a copy of SwipeGestureHelper, and more. This pretty much sums up to everything. So even though I can subclass SwipeNavigate I cannot use it like I want to.
I totally understand your reason, and your want to be able to update your libraries without thinking about what this breaks for others. However the pattern where a lot of old code is copyied around in projects is less desireable IMHO.