Title: CSCI 3005 ObjectOriented Programming
1CSCI 3005Object-Oriented Programming
- Chapter 1 Introduction to .NET Framework
2Outline
- Previous State of Affairs
- Overview of the .NET Framework
- Framework Class Library
- Common Language Runtime
- Common Intermediate Language
- Common Type System
- Common Language Specification
- What C Brings to the Table
3Previous State of Affairs
- Life As a C/Win32 API Programmer
- Life As a C/MFC Programmer
- Life As a Visual Basic 6.0 Programmer
- Life As a Java/J2EE Programmer
- Life As a COM Programmer
- Life As a Windows DNA Programmer
4Life As a C/Win32 API Programmer
- Traditional software development for the Windows.
- C developers are forced to contend with complex
memory management and pointer arithmetic. - It lacks the benefits provided by the
object-oriented approach - When you combine the thousands of global
functions and data types defined by the Win32 API
to an already formidable language, it is little
wonder that there are so many buggy applications
floating around today.
5Life As a C/MFC Programmer
- C is an object-oriented layer on top of C.
- Programmers benefit from the famed pillars of
OOP (encapsulation, inheritance, and
polymorphism). - Microsoft Foundation Classes (MFC) provides a set
of C classes that facilitate the construction
of Win32 applications. - It wraps a sane subset of the raw Win32 API
behind a number of classes, magic macros, and
numerous code-generation tools (wizards). - Regardless of the helpful MFC, programming for
Windows using C remains a difficult and
error-prone experience.
6Visual Basic 6.0 Programmer
- VB6 is popular due to its ability to build
complex user interfaces, code libraries, and data
access logic with minimal fuss and bother. - Even more than MFC, VB6 hides the complexities of
the raw Win32 API from view using integrated code
wizards, intrinsic data types, classes, and
VB-specific functions. - The downfall of VB6 (rectified given the advent
of Visual Basic .NET) is that it is not fully
object-oriented - VB6 does not allow the programmer to establish
is-a relationships between types (i.e., no
classical inheritance) - VB6 does not provide the ability to build
multithreaded applications unless you are willing
to drop down to low-level Win32 API calls (which
is complex at best and dangerous at worst).
7Life As a Java/J2EE Programmer
- The platform independent Java programming
language is object oriented and has its syntactic
roots in C. - Java cleans up many unsavory syntactical aspects
of C. - Java provides programmers with a large number of
predefined packages that contain various type
definitions. - While Java does provide a limited ability to
access non-Java APIs, there is little support for
true cross-language integration. - Pure Java is not appropriate for many graphically
or numerically intensive applications (in these
cases, you may find Javas execution speed leaves
something to be desired). - A better approach for such programs would be to
use a language such as C where appropriate.
8Life As a COM Programmer
- The Component Object Model (COM) was Microsofts
previous application development framework. - If you build your classes in accordance with the
rules of COM, you end up with a block of reusable
binary code. - C programmers can build COM classes that can be
used by VB6. Delphi programmers can use COM
classes built using C. - COMs language independence is limited.
- There is no way to derive a new COM class using
an existing COM class (as COM has no support for
classical inheritance). - Rather, you must make use of the more cumbersome
has-a relationship to reuse COM class types. - COM is extremely complex under the hood.
- The Active Template Library (ATL) provides a set
of C classes, templates, and macros to ease the
creation of COM types.
9Life As a Windows DNA Programmer
- Microsoft has been adding more Internet-aware
features into its family of operating systems and
products. - COM-based Windows Distributed interNet
Applications Architecture (DNA) is quite complex. - Due to the simple fact that Windows DNA requires
the use of numerous technologies and languages
(ASP, HTML, XML, JavaScript, VBScript, COM(),
and data access API like ADO). - The problem is that many of these technologies
are completely unrelated from a syntactic point
of view. - JavaScript has a syntax much like C, while
VBScript is a subset of VB6. The result is a
highly confused mishmash of technologies. - Each language and/or technology has its own type
system An int in JavaScript is not quite the
same as an Integer in VB6.
10Overview of the .NET Framework
- The .NET Framework is designed as an integrated
environment for seamlessly developing and running
applications on the Internet, on the desktop as
Windows Forms, and even on mobile devices - To provide a consistent object-oriented
environment across the range of applications. - To provide an environment that minimizes the
versioning conflicts ("DLL Hell") that has
bedeviled Windows (COM) programmers, and to
simplify the code distribution/installation
process. - To provide a portable environment, based on
certified standards, C and a major part of the
.NET runtime, the Common Language Infrastructure
(CLI), that can be hosted by any operating
system. - To provide a managed environment in which code is
easily verified for safe execution.
11.NET is the result of many influences
OOP
JVM
GUI
.NET
Web
component-based design
n-tier design
12.NET is multi-language
- .NET supports VB, C (C-sharp), C, J (Java
1.2), etc.
code.vb
code.cs
code.cpp
...
FCL
Development Tools
app.exe
13.NET is cross-platform
- Compiled .NET apps run on any supported platform
APP.exe
?
Win32 (XP,2K,98)
Win64
WinCE
14How is cross-platform achieved?
- Cross-platform execution realized in two ways
- Apps are written against Framework Class Library
(FCL), not underlying OS - Compilers generate generic assembly language
which must be executed by the Common Language
Runtime (CLR)
- Framework Class Library
- 1000's of predefined classes
- common subset across all platforms languages
- networking, database access, XML processing, GUI,
Web, etc. - Goal? FCL is a portable operating system
15The Common Language Runtime (CLR)
- The CLR defines a common programming model and a
standard type system for cross-platform,
multi-language development. - All .NET-aware compilers generate Intermediate
Language (IL) instructions and metadata. - The runtime's Just-in-Time (JIT) compiler convert
the IL to a machine-specific (native) code when
an application actually runs. - Because the CLR is responsible for managing this
IL, the code is known as managed code.
16Intermediate Language (IL)
- All .NET-aware compilers generate Intermediate
Language (IL) instructions and metadata.
17Assemblies
- 1 assembly 1 or more compiled classes
- .EXE represents an assembly with classes Main
program - .DLL represents an assembly with classes
code.vb
code.vb
code.cs
Development Tools
.EXE / .DLL
assembly
18.NET Application Design
- Monolithic app all source code compiled into
one .EXE - not the norm on Windows
APP.exe
- Component-based app .EXE one or more .DLLs
- standard practice on Windows
compute.dll
GUI.exe
data.dll
- team programming
- multi-language development (I like C, you like
C, he/she likes VB) - code reuse (e.g. across different .EXEs)
- independent updating (update just component X)
- FCL ships as a set of components!
19CLR-based execution
- Common Language Runtime must be present to
execute code
APP.exe
OS Process
CLR
other FCL components
Core FCL
obj code
Underlying OS and HW
20CLR-based execution revisited
- CLR must be able to locate all assemblies
.DLL
.DLL
.EXE
.DLL
OS Process
CLR
other FCL assemblies
Core FCL assembly
obj code
obj code
obj code
obj code
Underlying OS and HW
21mscoree.dll - Common Object Runtime Execution
Engine
22Implications of .NET's execution model
- Clients need CLR FCL to run .NET apps
- available via Redistributable .NET Framework
- 20MB download
- runs on 98 and above, NT (sp6a) and above
- Design trade-off
- managed execution (memory protection, verifiable
code, etc.) - portability
- slower execution?
23The Common Type System (CTS)
- CTS is based on a hierarchy of classes defined in
FCL - all types inherit from Object (all except
interface types)
24CTS Data Types
- Language keywords map to common CTS classes
25The Common Language Specification (CLS)
- Not all languages support all CTS types and
features - C is case sensitive, VB.NET is not
- C supports pointer types (in unsafe mode),
VB.NET does not - C supports operator overloading, VB.NET does not
- CLS was drafted to promote language
interoperability - vast majority of classes within FCL are
CLS-compliant
26What C Brings to the Table
- C is a hybrid of numerous languages, which is as
syntactically clean as Java, is about as simple
as VB6, and provides just about as much power and
flexibility as C. - C looks very similar to the syntax of Java. Both
C and Java are based on the syntactical
constructs of C. - Like VB6, C supports properties (as opposed to
traditional getter and setter methods) and the
ability to declare methods taking varying number
of arguments (via parameter arrays). - Like C, C allows you to overload operators
without the complexity (e.g., no need for return
this to allow chaining), as well as to create
callback functions (via delegates). - No pointers required! C programs typically have
no need for direct pointer manipulation. - Automatic memory management through garbage
collection. Given this, C does not support a
delete keyword. - Full support for interface-based programming
techniques and aspect-oriented programming (AOP)
techniques via attributes.
27Summary
- .NET architecture is
- multi-language
- cross-platform
- based on the CLR, FCL, and JIT technology
- Application designs are typically component-based
- .NET components are packaged as assemblies