why do I need this reference ?

aw48

Active member
Joined
Feb 9, 2013
Messages
36
Location
Germany
Programming Experience
10+
hi,
can someone explain the following problem :
I have dll1 with class1. dll1 references dll2 with class2. class2 has a property "public bool IsFolder"
class1 has a property "public List<class2> Items"
In a form I reference dll1 and have an object "class1 obj"
So now when I say "if (obj.Items[0].IsFolder) ....." I get a compile-error which states my form has to reference dll2 and when I do so everything works fine.
Why does my form have to know about dll2 ?
thanks in advance
 
Since you (or the designers of class1) broke The Law of Demeter, then you have to pay the price.

If you go poking into the insides of class1 to access something in it, then the compiler needs to know about it (via adding a reference) because how else would it know if IsFolder is correct or not? What if your typed in IsAMoon or IsASpaceStation instead? Should the compiler just let it work?

C# is an early bound language (in general until you start playing with dynamic objects). This is different from late bound languages like JavaScript and VB6. Early bound languages need to know the details of things that you access at compile time. Late bound languages discover the details of things at run time.
 
Last edited:

Latest posts

Back
Top Bottom