7426718 Lecture 13 the NET Framework VB 2008

Embed Size (px)

Citation preview

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    1/19

    Lecture 13- The NET Framework

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    2/19

    Outline

    In the last lecture, we continued our discussion ofObjects

    By finishing our our own custom Collection: JTrainCollection

    By inheriting from the .NET System Class, CollectionBase.

    And illustrated its use, with a generalized Multiple-JTrain Example,

    Including the addition of two Shared Members.

    We now continue our discussion with some related topics: The .NET Framework and .NET Framework Classes

    Which provide us with a platform for Windows Application Development; And supporting basis for ourObject-oriented approach:

    Namespaces Which place a hierarchical structure on all .NET Classes

    Both the Framework Classes, and Developer Classes

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    3/19

    Inheriting From Object

    Think back to when we first defined JTrain

    We used a default New() Constructor provided by the System. Sowhere did this Constructor come from?

    Recall that we later used JTrains default Constructor

    When we made our first instance ofJFreightTrain:

    We used the Inherits Keyword to get this functionality:

    JFreightTrain Inherits from JTrain So, this type ofbehavior implies Inheritance.

    However, we did NOT use the Inheritskeyword when we defined JTrain.

    In turns out that all VBObjects automatically inherit from Object

    So that the Class Object serves as the universal Base Class.

    Even though the VB Keyword Inherits is not necessary, for this.

    Several useful methods are thus available from Object, including:

    ToString() : returns a String representation of the Object (weve used this).

    GetType() : returns a Type Object, representing the Objects data type

    This brings us to a discussion of the .NET Framework Classes

    To discuss this, we first need to discuss the .NET Framework.

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    4/19

    Windows Application Development

    In this class, we have discussed Windows Application Development Now, lets talk a little bit about the underlying systems

    The .NET platform and how it relates to Objects.

    The Windows O.S. and its interface with developed software.

    All software written by developers must communicate with Windows:

    To store data, a block of memory must be reserved:

    The Windows Memory Manageris called.

    To write data to the disk:

    The Windows Disk Subsystem is called.

    To draw a Window on the screen:

    The WindowsGraphics Subsystem is called.

    This communication is supported by the Win32 API

    The Windows 32 Abstract Programming Interface.

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    5/19

    The Windows 32 API

    The Win API provides a layer of abstraction via a set ofinterfaces And a set of associated programs for implementing these interfaces.

    Each of which provides a standard hand-shake with a Windows Subsystem.

    Examples:

    When a file is to be written or read, a standard DialogBox is provided:

    From the APIs Common Dialog Box Library. When a Window is to be drawn on the screen:

    The APIs User Interface is used, together with the Common Control Library.

    In the past, Windows developers used the Win32 API directly

    Using a Software Development Kit (SDK) which included:

    The Win32 API. Tools to assist in use of the Win32 APU.

    However: theAPI is difficult to learn and tricky to use!

    Ex: Roughly 100 lines of code required to draw a basic Window.

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    6/19

    VB: Abstracting away the API

    VB helped by providing developers with a big simplification:

    Tricky API functions were packaged in an user-friendly way. In VB, a Window can be drawn with only a few lines of code

    Which provide many more details, hidden underneath

    Thus, VB provides anAbstraction Layeron top of the Windows API

    So users dont have to deal with the API directly.

    This was greatly responsible for the big success of VB.

    This situation was quite frustrating for non-VB developers

    C++ and Java developers have their own advantages:

    C++ provides lots of control over program function...

    Java makes programs extremely portable.

    However, development tasks that are easy in VB

    e.g., GUI development.

    Take a really long time in Java, for instance.

    This VB-Windows dependency was also dangerous for Microsoft:

    What happens if Windows is no longer dominant in 20 years?

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    7/19

    The .NET Framework Classes

    In 1992, Microsoft improved this situation quite a bit....

    By introducing the Microsoft Foundation Classes (MFC) A set of C++ Classes, each of which provides a wrapper:

    Encapsulating and simplifying an API function.

    Essentially, providing an Object Oriented layer of abstraction on the API.

    Along with the Visual Studio IDE.

    Later, Microsoft recast this concept within the larger.NET Framework.

    The .NET Framework is completely object-oriented:

    Anything done in .Net will be done using an Object.

    Ex: To to open a file, you use a System Object designed for this purpose.

    This set of objects is actually a huge set ofBase Classes (approx. 3500)

    called the .NET Framework Classes.

    All .NET developers will use this same set of classes

    Regardless of the platform they are on!

    Windows, Linux, Pocket PC, Mac

    Very developer-friendly!

    Regardless of the high-level language (HLL) they choose!

    VB .NET, C++, C#, J# (.NET version of Java), etc.

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    8/19

    Common Language Infrastructure

    This is accomplished by compiling HLL code in two steps:

    First to Microsoft Intermediate language:

    CIL (Common Intermediate Language; also called MSIL).

    All high-level languages are compiled to this same CIL code.

    This language is NOT dependent on any processor or platform.

    Then to platform-specific native (machine) code later on

    At runtime, by the Common Language Runtime (A Virtual Machine): So-called Just-In-Time (JIT) Compilation.

    So, the Common Language Infrastructure, CLI = CIL + CLR

    In this way, Microsoft freed itself from its dependence on Windows

    As well, in principle, as its dependence on Intel Chip sets.

    Note that the Java concept is similar:

    It is also compiled to an intermediate language, called Byte Code.

    Which then runs in the Java Virtual Machine.

    However, while Java is One Language / Many Platforms

    .NET started as Many Languages / One Platform (and then expanded).

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    9/19

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    10/19

    Achieving Language Interoperability

    Language interoperability in .NET goes beyond common compilation:

    The idea is really much more general:

    It would be best if classes which are defined/extended in one language

    Are then freely available to all.

    Example: Our JTrain Class should be extendable by a C# Programmer

    So that the Classes will function properly in a C# program (!)

    .NET introduced the Common Type System (CTS) to support this: Primitive data types are handled the same in all managed languages

    Integers, Doubles, Strings, etc are defined consistently.

    Previously, they were defined differently, in different HLLs.

    This simplifies thejob of interoperabilitybetween languages.

    .NET also introduced the Common Language Specification (CLS): Along with managed code comes the concept of managed data

    Nearly all CLR-managed Data are represented as Objects.

    Specifically: Classes in the .NET Framework and derived Classes

    These can be passed between managed languages.

    This brings us back to the .NET Framework

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    11/19

    Overview of the CLI

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    12/19

    The .NET Framework Classes

    The .NET Framework consists of two components:

    The Common Language Runtime (Actually, the CLI).

    The .NET Framework Classes.

    A huge set (> 3500) ofBase Classes for developer use.

    A bit hard to navigate

    Fortunately, the Framework Classes are conveniently divided intorelated groups.

    Each group is associated with a specific Namespace.

    The overall collection of namespaces is hierarchical:

    Namespaces can contain other namespaces.

    Created by stringing together the namespaces with the dot (.) operator

    Each class must belong to exactly 1 namespace:

    Its containing namespace, followed by its specific Class name.

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    13/19

    The System Namespace

    Most Framework Classes are contained in the System namespace.

    In fact, we have alreadybeen using System Classes extensively

    Examples:

    System.Windows.Forms Classes for drawing Forms

    System.Console A Class for designing Console Applications

    System.Object Here, we see that Object derives from Class System.

    We were allowed to use abbreviated versions

    Ex: We used Console.ReadLine() rather than System.Console.ReadLine()

    Now, we talk about finding Namespaces and Namespace Creation:

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    14/19

    Finding the Current Namespace

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    15/19

    Using the Object Browser

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    16/19

    Creating YourOwn Namespace

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    17/19

    Multiple Inheritance

    Some languages support Multiple Inheritance

    By which Objects can combine behaviors from several superclasses.

    Sounds interestingbut this can cause ambiguity troubles.

    Examples:

    C++ permits multiple inheritance

    Java technically does not

    but supports the use of multiple interfaces, instead.

    In the .NET Framework, Multiple-inheritance is not allowed.

    Each Class must be derived (directly inherit) from exactly one Class.

    In other words, only 1 Class can be included in a Classs Inherits Clause.

    Recall: all Objects ultimately inherit from System.Object

    For derived Classes, there will be a chain of inheritance-relationships:

    JFreightTrain inherited from JTrain

    JTrain inherited from System.Object.

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    18/19

    Preview: Software Engineering

    In the next course, we continue with our tour of VB .NET: Advanced topics in OO Programming, including:

    Partial and Abstract Classes

    Interfaces and Generics

    Creating Class Libraries

    Which encapsulate related sets of Classes for re-use. Registering your Libraries

    So that you can find the classes ofyour library with the Object Browser.

    Creating Custom Controls

    Custom Graphics

    Then, some related technologies:

    Database Access (ADO.NET) Server-Side Programming (ASP.NET)

    In the Software Engineering Seminar, we will discuss using C# ....

    This will allow us to do Embedded Programming ( Course 4 ) You may not get much C# until the seminar.

    We will probably look at J# concurrently (Microsofts version of Java)

  • 8/8/2019 7426718 Lecture 13 the NET Framework VB 2008

    19/19

    Conclusion and Final Project

    In this Course, we discussed Application Programming Fundamentals:

    Specifically: development for Windows Applications.

    Along the way, we discussed:

    The most frequently-used Controls.

    Basic and Advanced topics in Object Oriented Programming.

    In the next course, we will continue with a more VB .NET:

    Advanced OO Topics

    Creating Class Libraries

    Creating Custom Controls

    Custom Graphics.

    Then, some related technologies:

    Database Access (ADO.NET) Server-Side Programming (ASP.NET)

    The C# language will be discussed in my seminar

    To allow us to do Embedded Programming ( Course 4 )

    Now, lets discuss yourFINAL PROJECT.