Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bad practice. Or Not ?
Message
General information
Forum:
ASP.NET
Category:
Class design
Environment versions
Environment:
C# 4.0
Miscellaneous
Thread ID:
01492859
Message ID:
01493202
Views:
61
>>Hi,
>>Given:
public class A {}
>>public class B
>>{
>>    public static implicit operator B(A a) { return new B(); }
>>    public static implicit operator C(B b) { return new C(); }
>>}
>>public class C {}
Would you find a statement like this too opaque:
C c = (B)new A();
>
>Yes (assuming this convention isn't used a lot in the code). I wouldn't have a clue as to why that was working (and I'd probably be annoyed that had to dig through the class to figure out what it was doing/why it worked). But if it's used a lot in the code and made the overall code more readable, then all is forgiven <g>

I decided to make the operators explicit for readability. An alternative would have been to give B a constructor that took an instance of A and to give C a constructor that took an instance of B - but that looks even worse :-{ :
C c = new C(new B(new A()));
Previous
Reply
Map
View

Click here to load this message in the networking platform