View Single Post
  #7 (permalink)  
Old March 6th, 2009, 02:15 PM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

you inherit something to make it behave a certain way. In my case like a page or a masterpage for pages and masterpages respectivly?
Yes, correct. By inheriting a class, you actually *extend* it. So, you get everything your base class can do, and have the ability to add your own behavior. With the BasePage class, you get everything that System.Web.UI.Page can do, and the ability to check the Title propeprty (although that's just an example; you could do many more things of course).

My next question is what is the namespace? Is that the system.web.ui and then the class file "page" gives it the specific behaviour of a page.
Is a namespace a collection of class files?
No, not really. Take another look at page 171 and onwards. Namespaces are just names you can make up to *uniquely identify) a class. The examples uses a (fictitious) Microsoft.Office.Word.Page class where Microsoft.Office.Word is used to avoid a name collision with the System.Web.UI.Page class.

They also allow you to easily group classes. In that respect your comment on a "collection of class files" is more or less correct. However, classes are compiled into DLL files (called Assemblies) which holds a collection of classes. These classes can be placed in many namespaces inside the same assembly. Also, a namespace can be spread out over multiple assemblies. So, the namespace are just used to group things logically, and are not really the "container of classes"....

Therefore you couldn't have a masterpage inherit it because it inherits a different class?
Exactly. A MasterPage needs Master behavior; not Page behavior. Just as a Cow needs Animal behavior, and not Vehicle behavior.
And stick more logic bits in the basepage that give it extra functionality than the normal class.
Exactly. By extending the base class, your class gets more behavior than its base class.

Hope this clarifies things further.


Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote