SlideShare a Scribd company logo
Creating Components


Objectives
    In this lesson, students will learn to:
         • Identify the types of components
         • Identify the various stages in the life cycle of a component
         • Implement polymorphism in components
         • Use .NET COM components in VB.NET
         • Declare properties and methods for a component
         • Create a reference of the Component from the User Interface
         • Identify the role of assemblies in VB.NET




 ©NIIT        Creating and Managing Components              Lesson 1A / Slide 1 of 24
Creating Components


Getting Started with .NET
Components
    •    A component is a binary executable built from a .NET project.
    •    The component is referenced by applications seeking the services provided by
         the component.




 ©NIIT          Creating and Managing Components              Lesson 1A / Slide 2 of 24
Creating Components


Introducing Components
    •    You can create the component once and reuse it whenever necessary.
    •    You can also develop components as a third party provider.
    •    When you use the components, you are not inheriting a class but using a
         binary code in your applications.




 ©NIIT          Creating and Managing Components              Lesson 1A / Slide 3 of 24
Creating Components


Types of Components
    •    Components can be of three types:
          • In-built Components
               • The .NET class framework comes with in-built components, such as
                 Timer and ServiceController.
               • You can use the components that come with the .NET class
                 framework in your applications.
          • Component Classes
               • A class becomes a component when it follows defined standards of
                 interaction.
               • All components derive from the Component class.
          • User Controls
               • User Controls can be defined as bundles of standard controls.



 ©NIIT          Creating and Managing Components            Lesson 1A / Slide 4 of 24
Creating Components


Characteristics of a Component
    •    The name of a component class should be short and meaningful. It should be a
         combination of whole words with a capitalized initial character for each word.
    •    You can control the use of a component by using proper access level for the
         constructors.
    •    You can implement the IComponent interface to create a component.
    •    You should group related components together in separate namespaces.




 ©NIIT          Creating and Managing Components              Lesson 1A / Slide 5 of 24
Creating Components


Life Cycle of a Component
    •    Components are initialized by constructors.
    •    Initialization can be of two types:
           • Type initialization
                  • Type initialization is achieved by using a shared constructor.
                  • Shared constructor is called only once in the lifetime of a Visual Basic
                     .NET application.
           • Instance initialization.
                  • Instance initialization can be achieved by using constructors, which
                     are not shared.




 ©NIIT           Creating and Managing Components                 Lesson 1A / Slide 6 of 24
Creating Components


Polymorphism in Components
    •    The ability of a class to implement functions with the same name that are
         performing different actions depending on how they are called is known as
         polymorphism.
    •    Polymorphism can be implemented by:
           • Implementing an interface.
           • Inheritance
           • Using abstract classes.




 ©NIIT          Creating and Managing Components              Lesson 1A / Slide 7 of 24
Creating Components


Implementing Interfaces
    •    An   interface defines the behavior of a class.
    •    An   interface can declare properties, methods, and events.
    •    An   interface can be implemented by more than one class.
    •    An   interface can be declared as :
                    Interface interfacename
                           Sub functionname()
                    End Interface




 ©NIIT            Creating and Managing Components              Lesson 1A / Slide 8 of 24
Creating Components


Using .NET COM Components in
VB.NET
    •    Component Object Model (COM) was used in earlier versions of Visual Basic to
         create components.
    •    Implementation of COM is called ActiveX.
    •    The .NET supports COM and ActiveX objects for backward compatibility.
    •    A COM component from .NET can be called in the following ways:
           • By converting the COM type library to a .NET assembly.
           • Using COM components directly.




 ©NIIT          Creating and Managing Components              Lesson 1A / Slide 9 of 24
Creating Components


Converting COM Type Library to .NET
Assembly
    •    The tlbimp tool can be used to convert a COM type library to a .NET assembly.
    •    Following options can be used with tlbimp tool:
           • out:FileName – specifies the name of the assembly to be produced.
           • Namespace:NameSpace – Specifies the namespace of the assembly to be
              produced.
           • AsmVersion:Version – Specifies version number of the assembly to be
              produced.
           • reference:FileName – Specifies the file name to be used to resolve
              references.




 ©NIIT          Creating and Managing Components             Lesson 1A / Slide 10 of 24
Creating Components


Using COM Components Directly
    •    The Com components can be added directly through Solution Explorer in .NET.
    •    Internally, an Runtime Callable Wrapper (RCW) is used to access the COM
         components.




 ©NIIT          Creating and Managing Components            Lesson 1A / Slide 11 of 24
Creating Components


Using COM+ with VB.NET
    •    COM+ is the basic COM and a set of additional services.
    •    COM+ programming is based on the following assumptions:
           • In COM+, clients program on the basis of Interfaces, not Classes.
           • Code is not linked statically.
    •    Using Com+ components, you can focus on developing business logic.
    •    A .NET component that takes advantage of COM+ services needs to be derived
         from the .NET base class ServicedComponent.




 ©NIIT          Creating and Managing Components           Lesson 1A / Slide 12 of 24
Creating Components


Properties and Methods for a
Component
    •    To create a component in .NET, the user needs to identify:
           • The type of component.
           • Properties for the component.
           • Methods for the component.




 ©NIIT           Creating and Managing Components            Lesson 1A / Slide 13 of 24
Creating Components


Using Constructors
    •    A component can have the following types of constructors:
           • Public constructors.
           • Friend constructors.
           • Private constructors.




 ©NIIT          Creating and Managing Components             Lesson 1A / Slide 14 of 24
Creating Components


Adding properties
    •    Declaring a property allows you to control how a value is changed or read.
    •    Calculated values can be shown as properties even when they are not stored
         as actual data in the class.
    •    Property statement can also incorporate error handling.




 ©NIIT          Creating and Managing Components            Lesson 1A / Slide 15 of 24
Creating Components


Adding methods
    •    If a method is declared Private, only methods within the same class can call
         that method.
    •    A method in a class is a procedure that performs some sort of operation on the
         data within the class and may or may not return.
    •    A method is declared as:
              Public Function functionname() As Integer




 ©NIIT          Creating and Managing Components             Lesson 1A / Slide 16 of 24
Creating Components


Referencing the Component from the
User Interface
    •    A component can be tested only by referencing it from another application.
    •    A component can be referenced by using the Solution Explorer.




 ©NIIT          Creating and Managing Components             Lesson 1A / Slide 17 of 24
Creating Components


Role of Assemblies in VB.NET
    •    Concept of assemblies has been introduced in the .NET to counter the problems
         faced in DLL handling in previous versions.
    •    An assembly usually consists of:
            • Manifest
                 • This contains the information like name and version of the assembly.
                 • Information about the files that the assembly uses, is also present in
                   it.
            • Portable executable (PE)
                 • This contains metadata, Intermediate Language (IL) and the type
                   information.




 ©NIIT           Creating and Managing Components              Lesson 1A / Slide 18 of 24
Creating Components




                  Demo
         Using .NET Components




 ©NIIT   Creating and Managing Components   Lesson 1A / Slide 19 of 24
Creating Components

Problem Statement
    •    Build a .NET DLL component ‘PickServerTime’ which can get the current date
         and time from the host computer and then use the component in another
         VB.NET application named as ConsumerApplication which will display the
         information.




 ©NIIT        Creating and Managing Components            Lesson 1A / Slide 20 of 24
Creating Components


Solution
    •    To build and use the ‘PickServerTime’ component in an application named as
         ‘ConsumerApplication’ , you need to perform the following steps:
         1.   Create a project.
         2.   Add properties and functions to the component.
         3.   Build the component.
         4.   Create a user interface to test the component.




 ©NIIT        Creating and Managing Components            Lesson 1A / Slide 21 of 24
Creating Components


Summary
    In this lesson, you learned that:


    •    A component is a reusable piece of code in binary form that can be used
         along with the components from other vendors, with relatively little effort.
    •    Types of Components:
         • In-built components.
         • Component classes.
         • User controls.
    •    A component goes through different stages once you deploy it. The
         constructors initialize components.
    •    Initialization can be of two types:
         • Type initialization.
         • Instance initialization.


 ©NIIT         Creating and Managing Components              Lesson 1A / Slide 22 of 24
Creating Components


Summary (Contd.)
    •    In .NET programming environment, COM components are called:
         • By converting the COM type library to a .NET assembly.
         • By using COM components directly.
    •    The tlbimp tool uses the metadata of a COM type library to do the
         conversion.
    •    To create a component in .NET, the user firstly needs to identify the type of
         component and also its properties and methods.
    •    In .NET programming environment, a component can have the following
         types of constructors:
         • Public constructor.
         • Friend constructor.
         • Private constructor
    •    An assembly contains information about the files on which the component
         depends and the location of these files.
    •    An assembly consists of a manifest and the portable executables (PE).

 ©NIIT         Creating and Managing Components              Lesson 1A / Slide 23 of 24
Creating Components


Summary (Contd.)
    •    A manifest consists of information such as the name and version of the
         assembly.
    •    A portable executable consists of the IL code, type information, and
         metadata.




 ©NIIT         Creating and Managing Components            Lesson 1A / Slide 24 of 24

More Related Content

PPS
Vb.net session 16
PPS
Dacj 2-2 c
PPS
Vb.net session 06
PPS
Dacj 4 1-c
PPS
Dacj 4 1-b
PPS
Dacj 4 2-c
PPS
Dacj 4 2-b
PPTX
Entity Framework v1 and v2
Vb.net session 16
Dacj 2-2 c
Vb.net session 06
Dacj 4 1-c
Dacj 4 1-b
Dacj 4 2-c
Dacj 4 2-b
Entity Framework v1 and v2

Similar to Vb.net session 09 (20)

PPS
Vb.net session 10
PPS
Vb.net session 13
PPS
Vb.net session 01
PPS
Vb.net session 03
PPTX
.net Based Component Technologies
PPS
Vb.net session 02
PPTX
About .net
PPTX
Building extensible application using MEF
PPTX
Component based software engineering
PPS
Vb net xp_13
PPS
Ajs 2 c
PPTX
UNIT IV DESIGN PATTERNS.pptx
PPTX
Modular PHP Development using CodeIgniter Bonfire
DOC
10265 developing data access solutions with microsoft visual studio 2010
PPS
Vb.net session 04
PDF
jenkins.pdf
PDF
Jenkins_1679702972.pdf
PPT
Dot net Online Training | .Net Training and Placement online
PPS
08 gui 11
PPTX
Koala component model (1)
Vb.net session 10
Vb.net session 13
Vb.net session 01
Vb.net session 03
.net Based Component Technologies
Vb.net session 02
About .net
Building extensible application using MEF
Component based software engineering
Vb net xp_13
Ajs 2 c
UNIT IV DESIGN PATTERNS.pptx
Modular PHP Development using CodeIgniter Bonfire
10265 developing data access solutions with microsoft visual studio 2010
Vb.net session 04
jenkins.pdf
Jenkins_1679702972.pdf
Dot net Online Training | .Net Training and Placement online
08 gui 11
Koala component model (1)
Ad

More from Niit Care (20)

PPS
Ajs 1 b
PPS
Ajs 4 b
PPS
Ajs 4 a
PPS
Ajs 4 c
PPS
Ajs 3 b
PPS
Ajs 3 a
PPS
Ajs 3 c
PPS
Ajs 2 b
PPS
Ajs 2 a
PPS
Ajs 1 a
PPS
Ajs 1 c
PPS
Dacj 4 2-a
PPS
Dacj 4 1-a
PPS
Dacj 1-2 b
PPS
Dacj 1-3 c
PPS
Dacj 1-3 b
PPS
Dacj 1-3 a
PPS
Dacj 1-2 c
PPS
Dacj 1-2 a
PPS
Dacj 1-1 c
Ajs 1 b
Ajs 4 b
Ajs 4 a
Ajs 4 c
Ajs 3 b
Ajs 3 a
Ajs 3 c
Ajs 2 b
Ajs 2 a
Ajs 1 a
Ajs 1 c
Dacj 4 2-a
Dacj 4 1-a
Dacj 1-2 b
Dacj 1-3 c
Dacj 1-3 b
Dacj 1-3 a
Dacj 1-2 c
Dacj 1-2 a
Dacj 1-1 c
Ad

Recently uploaded (20)

PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Mushroom cultivation and it's methods.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Approach and Philosophy of On baking technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Programs and apps: productivity, graphics, security and other tools
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Machine learning based COVID-19 study performance prediction
Diabetes mellitus diagnosis method based random forest with bat algorithm
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Network Security Unit 5.pdf for BCA BBA.
Heart disease approach using modified random forest and particle swarm optimi...
Mushroom cultivation and it's methods.pdf
OMC Textile Division Presentation 2021.pptx
NewMind AI Weekly Chronicles - August'25-Week II
A comparative analysis of optical character recognition models for extracting...
Approach and Philosophy of On baking technology
Encapsulation_ Review paper, used for researhc scholars
Advanced methodologies resolving dimensionality complications for autism neur...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Group 1 Presentation -Planning and Decision Making .pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

Vb.net session 09

  • 1. Creating Components Objectives In this lesson, students will learn to: • Identify the types of components • Identify the various stages in the life cycle of a component • Implement polymorphism in components • Use .NET COM components in VB.NET • Declare properties and methods for a component • Create a reference of the Component from the User Interface • Identify the role of assemblies in VB.NET ©NIIT Creating and Managing Components Lesson 1A / Slide 1 of 24
  • 2. Creating Components Getting Started with .NET Components • A component is a binary executable built from a .NET project. • The component is referenced by applications seeking the services provided by the component. ©NIIT Creating and Managing Components Lesson 1A / Slide 2 of 24
  • 3. Creating Components Introducing Components • You can create the component once and reuse it whenever necessary. • You can also develop components as a third party provider. • When you use the components, you are not inheriting a class but using a binary code in your applications. ©NIIT Creating and Managing Components Lesson 1A / Slide 3 of 24
  • 4. Creating Components Types of Components • Components can be of three types: • In-built Components • The .NET class framework comes with in-built components, such as Timer and ServiceController. • You can use the components that come with the .NET class framework in your applications. • Component Classes • A class becomes a component when it follows defined standards of interaction. • All components derive from the Component class. • User Controls • User Controls can be defined as bundles of standard controls. ©NIIT Creating and Managing Components Lesson 1A / Slide 4 of 24
  • 5. Creating Components Characteristics of a Component • The name of a component class should be short and meaningful. It should be a combination of whole words with a capitalized initial character for each word. • You can control the use of a component by using proper access level for the constructors. • You can implement the IComponent interface to create a component. • You should group related components together in separate namespaces. ©NIIT Creating and Managing Components Lesson 1A / Slide 5 of 24
  • 6. Creating Components Life Cycle of a Component • Components are initialized by constructors. • Initialization can be of two types: • Type initialization • Type initialization is achieved by using a shared constructor. • Shared constructor is called only once in the lifetime of a Visual Basic .NET application. • Instance initialization. • Instance initialization can be achieved by using constructors, which are not shared. ©NIIT Creating and Managing Components Lesson 1A / Slide 6 of 24
  • 7. Creating Components Polymorphism in Components • The ability of a class to implement functions with the same name that are performing different actions depending on how they are called is known as polymorphism. • Polymorphism can be implemented by: • Implementing an interface. • Inheritance • Using abstract classes. ©NIIT Creating and Managing Components Lesson 1A / Slide 7 of 24
  • 8. Creating Components Implementing Interfaces • An interface defines the behavior of a class. • An interface can declare properties, methods, and events. • An interface can be implemented by more than one class. • An interface can be declared as : Interface interfacename Sub functionname() End Interface ©NIIT Creating and Managing Components Lesson 1A / Slide 8 of 24
  • 9. Creating Components Using .NET COM Components in VB.NET • Component Object Model (COM) was used in earlier versions of Visual Basic to create components. • Implementation of COM is called ActiveX. • The .NET supports COM and ActiveX objects for backward compatibility. • A COM component from .NET can be called in the following ways: • By converting the COM type library to a .NET assembly. • Using COM components directly. ©NIIT Creating and Managing Components Lesson 1A / Slide 9 of 24
  • 10. Creating Components Converting COM Type Library to .NET Assembly • The tlbimp tool can be used to convert a COM type library to a .NET assembly. • Following options can be used with tlbimp tool: • out:FileName – specifies the name of the assembly to be produced. • Namespace:NameSpace – Specifies the namespace of the assembly to be produced. • AsmVersion:Version – Specifies version number of the assembly to be produced. • reference:FileName – Specifies the file name to be used to resolve references. ©NIIT Creating and Managing Components Lesson 1A / Slide 10 of 24
  • 11. Creating Components Using COM Components Directly • The Com components can be added directly through Solution Explorer in .NET. • Internally, an Runtime Callable Wrapper (RCW) is used to access the COM components. ©NIIT Creating and Managing Components Lesson 1A / Slide 11 of 24
  • 12. Creating Components Using COM+ with VB.NET • COM+ is the basic COM and a set of additional services. • COM+ programming is based on the following assumptions: • In COM+, clients program on the basis of Interfaces, not Classes. • Code is not linked statically. • Using Com+ components, you can focus on developing business logic. • A .NET component that takes advantage of COM+ services needs to be derived from the .NET base class ServicedComponent. ©NIIT Creating and Managing Components Lesson 1A / Slide 12 of 24
  • 13. Creating Components Properties and Methods for a Component • To create a component in .NET, the user needs to identify: • The type of component. • Properties for the component. • Methods for the component. ©NIIT Creating and Managing Components Lesson 1A / Slide 13 of 24
  • 14. Creating Components Using Constructors • A component can have the following types of constructors: • Public constructors. • Friend constructors. • Private constructors. ©NIIT Creating and Managing Components Lesson 1A / Slide 14 of 24
  • 15. Creating Components Adding properties • Declaring a property allows you to control how a value is changed or read. • Calculated values can be shown as properties even when they are not stored as actual data in the class. • Property statement can also incorporate error handling. ©NIIT Creating and Managing Components Lesson 1A / Slide 15 of 24
  • 16. Creating Components Adding methods • If a method is declared Private, only methods within the same class can call that method. • A method in a class is a procedure that performs some sort of operation on the data within the class and may or may not return. • A method is declared as: Public Function functionname() As Integer ©NIIT Creating and Managing Components Lesson 1A / Slide 16 of 24
  • 17. Creating Components Referencing the Component from the User Interface • A component can be tested only by referencing it from another application. • A component can be referenced by using the Solution Explorer. ©NIIT Creating and Managing Components Lesson 1A / Slide 17 of 24
  • 18. Creating Components Role of Assemblies in VB.NET • Concept of assemblies has been introduced in the .NET to counter the problems faced in DLL handling in previous versions. • An assembly usually consists of: • Manifest • This contains the information like name and version of the assembly. • Information about the files that the assembly uses, is also present in it. • Portable executable (PE) • This contains metadata, Intermediate Language (IL) and the type information. ©NIIT Creating and Managing Components Lesson 1A / Slide 18 of 24
  • 19. Creating Components Demo Using .NET Components ©NIIT Creating and Managing Components Lesson 1A / Slide 19 of 24
  • 20. Creating Components Problem Statement • Build a .NET DLL component ‘PickServerTime’ which can get the current date and time from the host computer and then use the component in another VB.NET application named as ConsumerApplication which will display the information. ©NIIT Creating and Managing Components Lesson 1A / Slide 20 of 24
  • 21. Creating Components Solution • To build and use the ‘PickServerTime’ component in an application named as ‘ConsumerApplication’ , you need to perform the following steps: 1. Create a project. 2. Add properties and functions to the component. 3. Build the component. 4. Create a user interface to test the component. ©NIIT Creating and Managing Components Lesson 1A / Slide 21 of 24
  • 22. Creating Components Summary In this lesson, you learned that: • A component is a reusable piece of code in binary form that can be used along with the components from other vendors, with relatively little effort. • Types of Components: • In-built components. • Component classes. • User controls. • A component goes through different stages once you deploy it. The constructors initialize components. • Initialization can be of two types: • Type initialization. • Instance initialization. ©NIIT Creating and Managing Components Lesson 1A / Slide 22 of 24
  • 23. Creating Components Summary (Contd.) • In .NET programming environment, COM components are called: • By converting the COM type library to a .NET assembly. • By using COM components directly. • The tlbimp tool uses the metadata of a COM type library to do the conversion. • To create a component in .NET, the user firstly needs to identify the type of component and also its properties and methods. • In .NET programming environment, a component can have the following types of constructors: • Public constructor. • Friend constructor. • Private constructor • An assembly contains information about the files on which the component depends and the location of these files. • An assembly consists of a manifest and the portable executables (PE). ©NIIT Creating and Managing Components Lesson 1A / Slide 23 of 24
  • 24. Creating Components Summary (Contd.) • A manifest consists of information such as the name and version of the assembly. • A portable executable consists of the IL code, type information, and metadata. ©NIIT Creating and Managing Components Lesson 1A / Slide 24 of 24