Women in Technology

Hear us Roar

  Making Sense of Partial Classes
Subject:   Can we extend the Class without inheriting an existing class
Date:   2004-12-10 03:39:24
From:   SK.NET
Writting a class code into multiple file may allow to extend the functionality of an existing Class in as seperate file.
What will happen if I have a class Account written in Account.vb and I write another file having partial Account class in Accounts_extend.vb
wont it violate the encapsulation because since this belong to same class so I can access the private members from my new defination. If this is true then there could be potential hazard using such approach.
I am not sure if I am correct in my understanding of partial class thats why I am posing the above query even if it may sound silly, but please clarify my understanding


Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • Can we extend the Class without inheriting an existing class
    2005-01-24 20:47:06  GersonK [View]

    In C# you have to use the "partial" modifier in the class decalaration in both files or it won't compile. So building the class partially is essentially just an implementation detail, hidden from other pieces of code.

    In VB.NET, as long as the files are in the same project, only one of them has to use the partial modifier. This seems like an invitation to mischief to me, but here's some defense of it from a member of the VB team :
    I can't find the promised separate posting explaining why VB.NET and C# behave differently in this area.