1 / 10

Programming with Objects: Class Libraries and Reusable Code

Programming with Objects: Class Libraries and Reusable Code. Objectives. Understand and employ the Visual Basic .NET classes, forms, components, modules, structures, and namespaces Understand the notion of a class library and its usefulness in creating reusable code

devika
Download Presentation

Programming with Objects: Class Libraries and Reusable Code

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming with Objects: Class Libraries and Reusable Code

  2. Objectives • Understand and employ the Visual Basic .NET classes, forms, components, modules, structures, and namespaces • Understand the notion of a class library and its usefulness in creating reusable code • Convert a Windows Forms application into a class library • Build a class library, and create a solution with multiple projects • Incorporate a component into a class library project, and use the component to exchange parameter data with a client program

  3. Understanding Classes, Forms, Components, Modules, Structures, and Namespaces • Principle of structured programming • Large programs should be subdivided into smaller, meaningful logical functional units • Class • Defines the properties, fields, methods, and events that go into an object • A reference type • Objectis an instance of a class • Can inherit from another class • Is both inheritable and reusable • Form • A type of class • Has a graphical component and a code component • May serve as a container for other forms • Must be instantiated as an object before it can be used • Code portion of a Windows form is loaded at the same time and on the same computer as the GUI

  4. Component • A class that conforms to a certain standard for interacting with other components • May or may not contain a graphical element • Can provide an easy way to communicate between projects in a solution • After component class has been instantiated, its methods are available

  5. Module • A reference type, consisting of declarations and procedures only • Similar to a class in terms of serving as a container for code • Unlike a class in several respects • Cannot be instantiated nor inherited • Cannot be nested inside another structure • Variables and procedures are shared by default • Public variables and procedures • Accessible and scoped to the namespace that contains the module

  6. Structure • An expansion of the user-defined type in previous releases of Visual Basic • Can contain different kinds of data items, each with its own accessibility • Is a value type (each variable based on a structure contains its own data) • Declared at the module or class level

  7. Declaration of structLogonPassword

  8. Namespace • Organizes the list of names that occur in an assembly • An assembly • The package that results from compilation • Can also contain lower-level namespaces • Reason for subdividing large project into namespaces • To avoid name collisions

  9. Compiling a Project into a Class Library • Class library • Defines a class • Great way to create reusable objects • Compiles to a DLL file (dynamic link library) • DLL file • Cannot be executed directly • Must be called from inside another running program • Output from the compiler is known as an assembly • After you have compiled your project into a class library • Executable project (or client) that calls this library must identify both the class library’s DLL file and its namespace name

  10. Summary • Class • Template or blueprint for an object • Form • Class that has both a graphical representation and a code segment • Component • Class designed for interaction with other components • Module • Contains code only and its data values are shared • Structure • Value type that defines fields, properties, methods, and events at the module level • Namespace • Defines a list of names (classes, structures, other namespaces, etc.) within an assembly • Class library • Defines a reusable program • Project compiled into a class library • Can receive ByVal or ByRef parameters from the calling (client) program • Method of passing parameters between programs • Through component class

More Related