Q^Q Posted December 16, 2021 Report Share Posted December 16, 2021 I just noticed that I can drag an interface onto block diagram and create an instance of the interface. But for most of the cases, I want the interface to be abstract. Is there any way to prevent users from creating instance from the interface I provided? Quote Link to comment
Francois Normandin Posted December 16, 2021 Report Share Posted December 16, 2021 No you cannot. Your simplified example, if the interface is truly abstract, is equivalent to trying to prevent someone from dropping a "empty string constant" on the block diagram. Fundamentally though, it would prevent you from using the direct cast to exercise the override, as shown in the bottom example. The only restriction is that one cannot create a DVR of the interface from outside the interface itself. I have to admit that I have not investigated the consequence of such a pattern in the context of interfaces... 1 Quote Link to comment
Q^Q Posted December 16, 2021 Author Report Share Posted December 16, 2021 Thank you for the answer! Quote Link to comment
Aristos Queue Posted December 16, 2021 Report Share Posted December 16, 2021 11 hours ago, Francois Normandin said: The only restriction is that one cannot create a DVR of the interface from outside the interface itself. The restriction on DVRs is the same for interfaces as for classes: it allows for constructor/destructor notation for by-reference entities. Please don't go hyper excited and think "Oh, this is the tool I should have been using all along." By-reference designs are fragile and prone to several classes of errors that by-value code cannot create. Stick to the wires where possible; use references only when nothing else serves! 🙂 Details here. 2 Quote Link to comment
Aristos Queue Posted December 16, 2021 Report Share Posted December 16, 2021 14 hours ago, Q^Q said: I just noticed that I can drag an interface onto block diagram and create an instance of the interface. But for most of the cases, I want the interface to be abstract. Is there any way to prevent users from creating instance from the interface I provided? As Francois noted, no, you cannot prevent it. The default instances are useful in many sentinel and error handling situations -- think like NaN in floating point. The defaults can also serve a role similar to "null" but without all the dangers of open references. Details about design decisions of interfaces can be found here. 1 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.