Presentatie over: "Programmeercursus O.O.P. met VISUAL BASIC.NET"— Transcript van de presentatie:
1Programmeercursus O.O.P. met VISUAL BASIC.NET Frans Vanrillaer & John Evans
2Wat is .NET.Net is het samen voegen van de ‘Common Language Runtime’ met een verzameling ‘.NET base classes’ ..Net laat ons:robuuste,foutvrije,aanpasbare,eenvoudig te installeren,goed te onderhouden,taal onafhankelijke,aangepast aan de moderne technologie,Programma’s ontwikkelen.
4Ontwikkelings Model Cliënt Database Cliënt Server Database Server One cannot appreciate .NET just by understanding its numerous features. To understand it in its correct perspective and realize what it is driving at one must take a broader look at what it is trying to address. So let us take a bird's eye-view of the overall software scenario. Firstly we need to understand what is the software development model that is adapted today and the problems that it faces. Secondly, we need to take a look at what different types of software applications are used today and what are the major concerns in developing these applications. Thirdly, we also need to a look at the places where the intelligence of the software application lies from a hardware perspective.Internet ExplorerOutlook ExpressCute FTPIISMS ExchangeConfigured IISMS WordMS ExcelSpell CheckerCharting Comp.
5Applicatie Types Word Windows Apps Excel Scheduler.dll Componenten Lib Chartmaster.dllWeb AppsElke Home pageE-Commerce SiteDistributie AppsBanking ApplicatieE-Commerce ApplicatieMobile AppsTrip-PlannerPocket-ReminderReal-TimeEmb. AppsFlight ControllerEngine Controller
6Intelligentie Plaats Mainframe Domme Terminal Intelligente Server PC With Intelligence I mean the shift which is happening over the years. In the Mainframe model there is an Intelligent server and number of dumb terminals acting as clients connected to the Intelligent server. All the processing is done on the server with clients acting merely as an interface to the server. Thus intelligence is concentrated on the server. In case of PCs one machine acts like a server as well as client. All the parts of the software are on the single machine. Hence intelligence lies only one machine. With the advent of LANs once again an intelligence shift happened once again. In a LAN intelligence lies on both client as well as server. This distribution is more or less equal. If you take a look at the Internet model the intelligence has once again been shifted back on the server. Clients are not like dumb terminals. Instead they have an application like browser that allows us to interact with the server applications. They can be called "not so dumb" terminals.De Twee samenNetwerkIntelligente ?Intelligente ?
7De .NET oplossing .NET Framework .NET Servers Ontwikkelings omgeving CLRBase ClassesSQL ServerBizTalk ServerCommerce ServerExchange ServerISA ServerMobile IISCLR = Common Language RuntimeBCL = Base Class LibraryFCL = Frame Class LibraryVisual Studio.NetÉén ontwikkelings omgeving(IDE ) voor alle software typesen alle .Net talen
8.NET Interne opbouw Taal Infrastructuur Common Type System VB.NETC#VC++.NETJ#.NETJScript…….Common Type SystemType declaratie (waarde of referentie)Type management (stack of heap)Basis functies volgens Object-Oriented ModelImplementatie regels voor nieuwe talen (CLS Common Language Specification)A developer can pick the .NET language that he likes most, write components in it, and share the compiled binary version of his component with other developers using other .NET languages. As on date there are 22 languages including VB.NET, VC++.NET, C#, COBOL, etc. from which the programmer can choose. Microsoft has made the specifications for .NET development platform freely available to compiler vendors in the form of Common Language Infrastructure (CLI). Vendors can develop compilers that produce standard binary code conforming to the CLI. CLI proposes a Common Type System which in turn contains Common Language Specification (CLS). The Common Type System defines how types are declared, used, and managed in the runtime. The common type system performs the following functions: · Defines how types should be declared (value or reference) and how they should be managed (stack or heap). · Provides base types in object-oriented form for languages to implement. · Defines rules that languages must follow, which helps ensure that types written in different languages can interact with each other. These rules are defined under the CLS. All .NET compliant languages have to follow the rules laid down by CLS to be truly interoperable. Some of these rules are listed below: Global variables and methods are not interoperable. If two variables are to be considered distinct, they must differ by more than just their case. Single type and name should not be used for a method and a variable. All dimensions of an array must have a zero lower bound. etc.
9.NET Interne opbouw Programming Model Common Type System Client-Side VB.NETC#VC++.NETJ#.NETJScript…….Common Type SystemClient-SideServer-SideMobile-SideWinFormsWinForm ControlsRich Client Apps.ComponentsWindows ServicesWebFormsWebForm ControlsWebServicesMobile WebFormsSmart ClientsReal-Time Apps.Now that we understand how .NET is able to provide true language interoperability without loosing important features of OO, let us now take a look at the differnet applications that one can develop in .NET using the same programming model and a single .NET compliant language. The slide lists various applications under different heads. The elegance of .NET is that if a form (WinForm) has been designed in C#, one can either use it as it is or inherit that form to add some more functionality before displaying it. This is known as Visual Inheritance. .NET has extended the WinForm technology to the Rich Client applications. Unlike Java Applets and Applications where one has to alter the code while converting an applet to an application or vice versa, the same WinForm can be used directly on the Web too. WinForm when used on Web runs under a secured environment on the client side without danger of accessing the client machine resources. WinForm controls as compared to ActiveX controls can now be easily developed (by just inheriting a class) and can be used in the different languages. A class library can be developed without any problem of DLL Hell or a deployment nightmare. This is because .NET components are fully self-describing without any dependencies on separate files. They can be conveniently versioned and accessed depending on the version number. Web applications can now be developed as easily and consistently as Windows applications. WebForms can be designed by drag and drop method. Events from the controls can be linked to handlers in the code. The output of the WebForm is displayed in the browser on the client-side, whereas, handlers for buttons and other controls execute on the server. WebForm controls like WinForm controls can be easily developed. Creation of Mobile WebForms is also possible through simple drag and drop. WebServices extend the vision of distributed computing as they use the existing infrastructure of the Web as well as standard protocols. Mobile applications can now be easily developed with the introduction of .NET Compact Framework. It is also possible to develop Hard Real-Time applications with the introduction of Windows CE.NET.
10.NET Interne opbouw Base Class Library Common Type System Client-Side VB.NETC#VC++.NETJ#.NETJScript…….Common Type SystemClient-SideServer-SideMobile-SideBase Class LibraryThe .NET Framework includes a rich set of classes that provides the comprehensive functionality for any type of application one intends to develop. The applications that we saw in the previous slide would need functionalities like messaging, database access, security, drawing, and many more. All these functionalities can be provided through the classes present in the base class library. All the classes in the Framework Class Library are organized in different namespaces.GDI+NetworkingThreadingWebProtocolsMessagingSerializationSecurityReflectionTimersADO.NETWindowing
11Common Language Runtime .NET Interne opbouwRuntimeVB.NETC#VC++.NETJ#.NETJScript…….Common Type SystemClient-SideServer-SideMobile-SideBase Class LibraryOnce an application is developed and executed the runtime takes care of it. .NET provides a enhanced runtime, as compared to the one provided by Windows, which comprises of the components listed in the slide. When a .NET compliant language compiler compiles the source code it emits code in intermediate language (IL). This code is processor independent code. The Just-In-Time (JIT) Compiler that the Common Language Runtime (CLR) provides compiles this code to the processor specific code (native code) which is then executed. The advantage of the IL is that it can be executed wherever .NET is present. Hence if .NET runtime is ported on different operating systems our code would get automatically ported on those operating systems. Also, it increases the performance of the applications because when JIT compiles IL to the native code it emits the code that is efficient for the underlying processor. CLR handles object creation and destruction and hence relieves programmer from destroying the objects explicitly.CLR releases the object when they are no longer being used. Automatic memory management eliminates memory leaks as well as some other common programming errors. CLR also handles runtime errors and informs the concerned application about them. CLR also provides a secured environment when a WinForm application is downloaded from the Web Server. It also checks for the integrity of components when they are loaded. It also checks for the type safety when types are accessed from different applications. CLR extends the Windows runtime concept of process by providing application domains. This allows multiple EXEs to run within the same process, but in different application domains without the risk of interference and at a considerably improved performance.Common Language RuntimeJust In Time Comp.Garbage CollectionClass loadingSecure environmentHandling ExceptionsApplication Domains
12Common Language Runtime .NET Interne opbouwPlatformVB.NETC#VC++.NETJ#.NETJScript…….Common Type SystemClient-SideServer-SideMobile-SideBase Class LibraryIn spite of all the enhancements and power that the framework comprises, at the core it runs on Windows. The framework uses the functionality provided by Windows which is listed in the slide. The framework also provides services that are needed by enterprise applications and mission-critical applications. Since such services are provided by COM+, the framework borrows them from COM+. The services are listed in the slide.Common Language RuntimeWindowsCOM+ ServicesTransaction supportMessage QueuingObject PoolingLoad BalancingGUIMultitaskingEvent driven model
13Common Language Runtime .NET Interne opbouw.NET FrameworkVB.NETC#VC++.NETJ#.NETJScript…….Common Type SystemClient-SideServer-SideMobile-Side.Net FrameworkBase Class LibraryCommon Language RuntimeWindowsCOM+ ServicesWindows 2000 / NT / XP
14.NET Interne opbouw Hoe het werkt Uitvoering onder CLR VB.Net Source CodeILCompilerLinkerC#Source CodeILCompilerEXE ofDLLHaving understood the details of the .NET framework let us take a overview of the way a .NET based program works. Once our code is written, we compile it, and the compiler translates it to Microsoft Intermediate Language (MSIL). MSIL is a CPU-independent set of instructions that can be efficiently converted to native (CPU dependent) code. MSIL code is a language independent code. The Linker then links the IL code converted by one language compiler with the IL code compiled by another language compiler. The result is an EXE or DLL, containing the IL code, which is saved to disk. VS.NET comes with different language compilers to generate IL code. During execution the IL code and any requested functionality from the .NET base classes is brought together. The Just In Time (JIT) compiler processes the combined code creating managed native code (code that targets the runtime is called managed code) which is passed to the CLR. The runtime automatically handles object layout and manages references to objects, releasing them when they are no longer being used.ClassLibraryJITCompilerUitvoering onderCLRNativeCode
16VB.NET Console applicatie maken Start Visual Studio File | New | ProjectSelecteer: Console ApplicationVul naam in:voorbeeld1Geef locatieKlik OkCreëert : Module Module1
17Console Applicatie Automatische Code Imports System Module Module1 We maken het ons gemakkelijk en importeren expliciet de namespace SystemNoodzakelijk begin Keyword van een ModuleNaam vd ModuleWordt meestal geweizigdModule Module1Start naamSub Main( )Begin Keyword van een SubroutineConsole.WriteLine ( "Hello VB.NET" )Class van SystemFunctie van deze ClassEnd SubEnd ModuleSluit Subroutine afSluit Module afKlik ‘F5’ of L-muis klik op:
18Console Applicatie Met Command-Line Argumenten 1/2 Pas de code als volgt aan :Module Module1Sub Main ( ByVal args( ) As String ) Dim s As StringFor Each s In argsConsole.WriteLine ( s )Next End SubEnd ModuleImports SystemOm deze code te RUNNENSelect Start | Uitvoeren zoek met Browse naar het programma in de bin folder klik en type Frans Jan Nadine, dan klik OK.Andere manierWe can stretch the first program done above to add the ability of printing the command-line arguments that may be supplied while executing the program. The enhanced program is shown in the slide. There are two ways of supplying command line arguments to a program: - Select Start | Run from menu item following the program name with the arguments that we intend to provide . - Alternatively right click on the project name from the Solution Explorer. Select properties. A property page would be displayed. Click on the configuration properties and select the debugging option from it. Supply the command line arguments. The For Each loop walks through the args( ) array printing each command-line argument in the process.