SlideShare a Scribd company logo
1 of 24
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

Similar to Create .NET Components

Vb.net session 10
Vb.net session 10Vb.net session 10
Vb.net session 10Niit Care
 
Vb.net session 13
Vb.net session 13Vb.net session 13
Vb.net session 13Niit Care
 
Vb.net session 01
Vb.net session 01Vb.net session 01
Vb.net session 01Niit Care
 
Vb.net session 03
Vb.net session 03Vb.net session 03
Vb.net session 03Niit Care
 
.net Based Component Technologies
.net Based Component Technologies.net Based Component Technologies
.net Based Component Technologiesprakashk453625
 
Vb.net session 02
Vb.net session 02Vb.net session 02
Vb.net session 02Niit Care
 
Building extensible application using MEF
Building extensible application using MEFBuilding extensible application using MEF
Building extensible application using MEFRonak Thakkar
 
Vb net xp_13
Vb net xp_13Vb net xp_13
Vb net xp_13Niit Care
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxanguraju1
 
Modular PHP Development using CodeIgniter Bonfire
Modular PHP Development using CodeIgniter BonfireModular PHP Development using CodeIgniter Bonfire
Modular PHP Development using CodeIgniter BonfireJeff Fox
 
10265 developing data access solutions with microsoft visual studio 2010
10265 developing data access solutions with microsoft visual studio 201010265 developing data access solutions with microsoft visual studio 2010
10265 developing data access solutions with microsoft visual studio 2010bestip
 
Vb.net session 04
Vb.net session 04Vb.net session 04
Vb.net session 04Niit Care
 
Jenkins_1679702972.pdf
Jenkins_1679702972.pdfJenkins_1679702972.pdf
Jenkins_1679702972.pdfMahmoudAlnmr1
 
Dot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement onlineDot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement onlineGaruda Trainings
 
Koala component model (1)
Koala component model (1)Koala component model (1)
Koala component model (1)Saransh Garg
 

Similar to Create .NET Components (20)

Vb.net session 10
Vb.net session 10Vb.net session 10
Vb.net session 10
 
Vb.net session 13
Vb.net session 13Vb.net session 13
Vb.net session 13
 
Vb.net session 01
Vb.net session 01Vb.net session 01
Vb.net session 01
 
Vb.net session 03
Vb.net session 03Vb.net session 03
Vb.net session 03
 
.net Based Component Technologies
.net Based Component Technologies.net Based Component Technologies
.net Based Component Technologies
 
Vb.net session 02
Vb.net session 02Vb.net session 02
Vb.net session 02
 
About .net
About .net About .net
About .net
 
Building extensible application using MEF
Building extensible application using MEFBuilding extensible application using MEF
Building extensible application using MEF
 
Component based software engineering
Component based software engineeringComponent based software engineering
Component based software engineering
 
Vb net xp_13
Vb net xp_13Vb net xp_13
Vb net xp_13
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
 
Modular PHP Development using CodeIgniter Bonfire
Modular PHP Development using CodeIgniter BonfireModular PHP Development using CodeIgniter Bonfire
Modular PHP Development using CodeIgniter Bonfire
 
10265 developing data access solutions with microsoft visual studio 2010
10265 developing data access solutions with microsoft visual studio 201010265 developing data access solutions with microsoft visual studio 2010
10265 developing data access solutions with microsoft visual studio 2010
 
Vb.net session 04
Vb.net session 04Vb.net session 04
Vb.net session 04
 
Jenkins_1679702972.pdf
Jenkins_1679702972.pdfJenkins_1679702972.pdf
Jenkins_1679702972.pdf
 
jenkins.pdf
jenkins.pdfjenkins.pdf
jenkins.pdf
 
Dot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement onlineDot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement online
 
08 gui 11
08 gui 1108 gui 11
08 gui 11
 
Koala component model (1)
Koala component model (1)Koala component model (1)
Koala component model (1)
 

More from Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 
Dacj 1-3 b
Dacj 1-3 bDacj 1-3 b
Dacj 1-3 b
 
Dacj 1-3 a
Dacj 1-3 aDacj 1-3 a
Dacj 1-3 a
 
Dacj 1-2 c
Dacj 1-2 cDacj 1-2 c
Dacj 1-2 c
 
Dacj 1-2 a
Dacj 1-2 aDacj 1-2 a
Dacj 1-2 a
 
Dacj 1-1 c
Dacj 1-1 cDacj 1-1 c
Dacj 1-1 c
 

Recently uploaded

The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Create .NET Components

  • 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