Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET 4.5
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Amazon Web Services
Analysis Services
Android
Architecture
Arduino
ASP .NET Web API
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
BDD
Big Data
Bing
BizTalk
Book Excerpts
Build and Deploy
Business Intelligence
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE Framework Info - non Technical
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Debugger
Design Patterns
Development Process
Display Technologies
Distributed Computing
Document Database
DotNetNuke
DSL
Dynamic Languages
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
HTML 5
Internet Explorer 8.0
Interviews
IOS
iPhone
Iron Ruby
Java
Java Script
JavaScript
jQuery
JSON
Lightswitch
LINQ
Linux
LUA
Mac OS X
MDX
Messaging
Metro
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
MVVM
MySQL
Network
NHibernate
node.js
NOSQL
Nuget
Object Oriented Development
Objective C
Odata
OLAP
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
PHP
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Prolog
Python
Q&A
Rails
Rake
Razor
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Scheme
Search
Security
Services
SharePoint
SignalR
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server 2012
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
TFS
Tips
TypeScript
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 11
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio 2011
Visual Studio 2012
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WebMatrix
WF
Whitepapers
Windows 7
Windows 8
Windows Azure
Windows Live
Windows Phone 7
Windows Phone SDK
Windows Server
Windows Vista
WinForms
WinRT
Workflow
WPF
XAML
Xiine Documentation
XML
XNA
XSLT



Component One


LearnNow
 


SSWUG

Reader rating:
Click here to read 8 comments about this article.
Article source: CoDe (2005 - Mar/Apr)


Article Pages:  1  2 3 4 5 - Next >


Implications and Repercussions of Partial Classes in the .NET Framework 2.0

Partial classes are a hot new feature of the next .NET compilers.Specifically designed to overcome the brittleness of tool-generated code, partial classes are a source-level, assembly-limited, non-object-oriented way to extend the behavior of a class. A number of advantages derive from intensive use of partial classes; for example, you can have multiple teams at work on the same component at the same time. In addition, you have a neat and elegant incremental way to add functionality to a class.

Until I got a copy of Jeff Prosise's book on MFC, I thought that Windows programming with MFC was only possible through wizards. In his book, Jeff showed me the way by creating a small but working MFC application without Visual Studio and its rich suite of wizards. Likewise, until I saw partial classes in action in Beta 1 of Whidbey, I thought that Windows Forms programming was only possible through wizard-like, and, frankly, bothersome, tool-generated code.

"
Whenever you set the DataSource property of a ComboBox control, the control retrieves and updates its binding context to reflect the new data source.
"

Technically speaking, a partial class is a class whose definition spreads over multiple and distinct source files. In real-world programming, there are several situations where splitting the definition of a class is desirable. By declaring a class partial, you state that source files can be added to the same project to extend the functionality of the class.

No hidden object-oriented principles lay behind partial classes?just the made-to-measure compiler's ability to build and process a class definition from various sources. Partial classes are a source-level, assembly-limited, non-object-oriented way to extend the behavior of a class.

In this article, I'll take a look at the motivation and definition of partial classes and the use you can make of them, especially in the context of Web applications.

Motivation for Partial Classes

If you have used Visual Studio .NET, you know about regions. A region is an IDE construct that expands and collapses blocks of source code. Regions were introduced with Visual Studio .NET and used mostly to hide tool-generated blocks of code. Tool-generated code is a characteristic inherited from Visual Basic 4. Remember FRM files?

You used to open FRM files in the IDE to see the graphical contents?buttons, textboxes, and any variety of controls. In the end, an FRM file was nothing more than a text file filled with the declaration of visual objects: their sizes, locations, component names and versions, and current properties. In Visual Studio .NET, the declarative part of the form is available per view but hidden in a collapsed region. Why is this code tool-generated? Because developers never get to write it.

When you drop a control onto a form, some code needs be generated to track the name, size, and location of the selected control. The IDE or wizards writes this code for you. You don't need to interact with this code; you can move or delete controls through the visual interface and the designer. Whenever this happens, the hidden code is properly adapted.

As you can tell, the model is effective because it works, but it's very brittle too. Any changes made to the hidden code can potentially break the application or component. Any crash or anomaly in Visual Studio .NET potentially leaves the code in an inconsistent state.

A form class (both Windows and Web) consists of declaration code plus action code. The two are logically separated but can't just be placed in physically separated classes, no matter the relationship between them. Partial classes are a way to work around the issue. Logic and declaration go into distinct files but compilers have to be updated to be able to process a class from multiple source files.

By marking a class as partial, you enable the compiler to retrieve the whole set of members from various files, perhaps written at different times by different developers.

&

By: Leonardo Esposito

Dino Esposito is the author of “Programming ASP.NET MVC” for Microsoft Press as well as “Programming ASP.NET 4” and other bestselling books such as “Microsoft ® .NET: Architecting Applications for the Enterprise”. Regular contributor to MSDN Magazine and DevProConnections Magazine, Dino is a frequent speaker at industry events all over the world including Microsoft TechED and DevConnections. After a decade of Web development, Dino jumped on the mobile bandwagon and is actively developing for iOs, Android and WP7.

leesposi@libero.it

Fast Facts

A partial class has its source code split over multiple source files, each of which appears to contain an ordinary class definition from beginning to end. Ideal for team development, partial classes simplify coding and avoid manual file synchronization in all those situations in which a mix of user-defined and tool-generated code is used, like Visual Studio .NET projects and ASP.NET pages.



Article Pages:  1  2 3 4 5 - Next Page: 'What's a Partial Class, Anyway?' >>

Page 1: Implications and Repercussions of Partial Classes in the .NET Framework 2.0
Page 2: What's a Partial Class, Anyway?
Page 3: Partial Classes Are a Framework Feature
Page 4: Usage of Partial Classes
Page 5: Partial Classes in ASP.NET

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
3.6 out of 5

39 people have rated this article.

Xojo

      AppsWorld Europe

 

Xojo