question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Breaking Change: Remove Unneeded Interfaces

See original GitHub issue

We currently have many interfaces in Avalonia which mirror concrete classes, for example (list is not exhaustive):

  • IAvaloniaObject -> AvaloniaObject
  • IControl -> Control
  • IInteractive -> Interactive
  • ILayoutable -> Layoutable
  • IPanel -> Panel
  • IStyledElement -> StyledElement
  • ITemplatedControl -> TemplatedControl
  • IVisual -> Visual

These interfaces were added at the beginning of the project at a time where the prevailing fashion in unit testing was “create an interface for each concrete class in order to make it easier to mock”.

This turned out to be a mistake because:

  • Using interfaces instead of concrete classes means that every method call is a virtual method call. This degrades performance in large applications and can be particularly noticeable when profiling on slower embedded and mobile hardware
  • We still target netstandard2.0 which includes platforms such as .NET framework where default interface implementations are not supported, meaning that we can’t even add methods to these interfaces without breaking API compatibility
  • Mocking is unnecessary in the unit tests anyway: it’s much better to use concrete classes
  • Implementing these interfaces in user code isn’t supported by much of the code anyway

For 11.0 we should remove these interfaces to improve performance. This will be a large breaking change, but we feel it’s necessary, and the fix should be reasonably straightforward - remove a bunch of I characters.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:10
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
amwxcommented, Nov 22, 2022

I think just making it a virtual read-only property on StyledElement would be best solution. Overridable things also show up in intellisense so probably more intuitive this way. Would be to simple fix in existing code too: Type IStyleable.StyleKey => typeof(MyControl); --> public override Type StyleKey => typeof(MyControl)

0reactions
grokyscommented, Nov 22, 2022

BTW, why aren’t we using the WPF approach with DefaultStyleKeyProperty?

Historical reasons really: back in 2015 when I didn’t know anyone would ever use this project, I decided to implement it like that. Mostly because in WPF, I always forgot the step of setting a new default value for DefaultStyleKeyProperty and it annoyed me because 90% of the time “of course I want a new style for this new control I’m writing”.

However if we want to change it to match WPF/UWP etc then now would be the time to do it. Bear in mind though that reading the default value of a styled property is a lot slower than reading a virtual CLR property, and we’d be potentially reading the property a lot more than WPF does due to our CSS-like styling system.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The removal of interfaces from v107 has made this library ...
Removal of interfaces is a change but compared with everything else it's not big. The number of breaking changes exceeds a handful.
Read more >
What problems will I face if I remove the concept of ...
Removing interfaces will disallow multiple inheritance from purely abstract classes. The remaining classes, instead of being multirooted ...
Read more >
Breaking an interface
If all consumers are rebuilt when you rebuild the interface then managing changing it is simple, simply change it and fix all the...
Read more >
Remove an unused/hidden network connection so that ...
1- Open Device Manager and in View tab enable Show hidden devices . 2- Find the device linked to network interface you want...
Read more >
Recommended usage for GraphQL interfaces
And because distributing an interface across subgraphs presents its own challenges, removing unnecessary interfaces usually makes life simpler.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found