Re: howto decouple in .NET?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Ben,

Sorry for the misunderstanding.

Perhaps you are looking for the mechanisms in C# for a ¡°compilation
firewall¡±, that is, a mechanism to decouple software components such that
both can compile independently and compilation propagation stops right
there. If that is the case, then the .NET interface type could help for
getting somehow similar effects, depending on the particular situation and
constraints, .NET reflection could be of help also.

In C++, one can inadvertently expose implementation details and increase
coupling: If Foo embeds a private member Bar, then every user of class Foo
also needs to know the layout of class Bar in order to use Foo. In managed
code, the problem doesn¡¯t exist ¨C if a class has a private member, the
rest of the world doesn¡¯t need to know of its existence. You can easily
verify this by declaring a public class Foo, which has a private reference
to an ¡°internal class Bar¡± declared in the same assembly.

However, using types ¡°in name only¡± is not possible in .NET. In C++, it
is possible for a class Foo to use Bar in its interface as an opaque handle
(if the public surface only refers to Bar* or Bar& and an instance of Bar
is NOT embedded in Foo, then the clients of Foo never need the definition
of Bar). Furthermore, if Foo never uses Bar directly in its implementation
(and only passes pointers or references to it to other components instead),
then Foo itself never needs the definition of Bar, either. This is not
achievable in C# - for instance, you cannot declare a public class Foo with
a public method taking or returning a Bar, if Bar is an internal class ¨C
you¡¯ll end up getting compiler errors.

If you are really committed to the lost art of uncoupling code, you might
want to look at ¡°the other way¡± of doing it ¨C declare Bar as internal
and don¡¯t use it in the public interface, but return and take IDs instead,
which you can then map to actual objects (in .NET, they can simply declare
their interface to use object and do some internal type checks prior to
using the thing). Note that there is a cost to this ¨C you will pay by
giving up some simplicity.

I don¡¯t think generics have anything to do with this. In .NET all types
must be fully defined at compilation time, generics is a run-time
mechanism, too late for a ¡°compilation firewall¡±.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

.



Relevant Pages

  • Re: self:: vs this
    ... I used them indistinctly and seemed to sort the same effects, although, when working with statics classes, self:: was the only way to access members. ... echo 'I am method Bar of Class Foo'; ... >> I am method Bar of Class Foo ...
    (php.general)
  • Re: pattern: auto-running module init code
    ... >You can also use super: ... > puts "in Bar" ... >class Foo < Bar ...
    (comp.lang.ruby)
  • Re: :CSV and multi character separator
    ... That is already available with or without an AS - FROM foo AS bar / FROM foo bar - both alias the table foo to the table bar. ... The current released version of DBD::CSV does not support this. ... and that module does not support multi-char separators. ...
    (perl.dbi.users)
  • Re: howto decouple in .NET?
    ... (if the public surface only refers to Bar* or Bar& and an instance of Bar ... is NOT embedded in Foo, then the clients of Foo never need the definition ... achievable in C# - for instance, you cannot declare a public class Foo ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Removing a class for good from ObjectSpace
    ... class Foo < Bar ... puts klass if Bar> klass ...
    (comp.lang.ruby)