SlideShare a Scribd company logo
1 of 27
Aggregation,
Namespaces, and
Advanced Scope
Overview
 Using Internal Classes, Methods, and Data
 Using Aggregation
 Using Namespaces
 Using Modules and Assemblies
Using Internal Classes, Methods, and
Data
 Why Use Internal Access?
 Internal Access
 Syntax
 Internal Access Example
Why Use Internal Access?
 Small objects are not very useful on their own
 Objects need to collaborate to form larger objects
 Access beyond the individual object is required
public
internal
private
Internal Access
 Comparing access levels
 Public access is logical
 Private access is logical
 Internal access is physical
internal
Syntax
internal class <outername>
{
internal class <nestedname> { ... }
internal <type> field;
internal <type> Method( ) { ... }
protected internal class <nestedname> { ... }
protected internal <type> field;
protected internal <type> Method( ) { ... }
}
protected internal means protected or internal
Internal Access Example
public interface IBankAccount { ... }
internal abstract class CommonBankAccount { ... }
internal class DepositAccount: CommonBankAccount,
IBankAccount { ... }
public class Bank
{
public IBankAccount OpenAccount( )
{
return new DepositAccount( );
}
}
Using Aggregation
 Objects Within Objects
 Comparing Aggregation to Inheritance
 Factories
 Example Factory
Objects Within Objects
 Complex objects are built from simpler objects
 Simpler objects are parts of complex whole objects
 This is called aggregation
CarWhole
Part EngineChassis Wheel
1 41
Comparing Aggregation to
Inheritance
 Aggregation
 Specifies an object relationship
 A weak whole-to-part dependency
 Dynamically flexible
 Inheritance
 Specifies a class relationship
 A strong derived-to-base dependency
 Statically inflexible
Part
Whole
Base
Derived
Factories
 Creation is often complex and restricted
 Many objects are made only in specialist factories
 The factory encapsulates the complex creation
 Factories are useful patterns when modelling software
Factory Example
public class Bank
{
public BankAccount OpenAccount( )
{
BankAccount opened = new BankAccount( );
accounts[opened.Number( )] = opened;
return opened;
}
private Hashtable accounts = new Hashtable( );
}
public class BankAccount
{
internal BankAccount( ) { ... }
public long Number( ) { ... }
public void Deposit(decimal amount) { ... }
}
Using Namespaces
 Scope Revisited
 Resolving Name Clashes
 Declaring Namespaces
 Fully Qualified Names
 Declaring using-namespace-directives
 Declaring using-alias-directives
 Guidelines for Naming Namespaces
Scope Revisited
 The scope of a name is the region of program text in
which you can refer to the name without qualification
public class Bank
{
public class Account
{
public void Deposit(decimal amount)
{
balance += amount;
}
private decimal balance;
}
public Account OpenAccount( ) { ... }
}
Resolving Name Clashes
 Consider a large project that uses thousands of classes
 What if two classes have the same name?
 Do not add prefixes to all class names
// From Vendor A
public class Widget public class VendorAWidget
{ ... } { ... }
// From Vendor B
public class Widget public class VendorBWidget
{ ... } { ... }

Declaring Namespaces
namespace VendorA
{
public class Widget
{ ... }
}
namespace VendorB
{
public class Widget
{ ... }
}
namespace Microsoft
{
namespace Office
{
...
}
}
namespace Microsoft.Office
{
}
shorthand
Fully Qualified Names
 A fully qualified class name includes its namespace
 Unqualified class names can only be used in scope
namespace VendorA
{
public class Widget { ... }
...
}
class Application
{
static void Main( )
{
Widget w = new Widget( );
VendorA.Widget w = new VendorA.Widget( );
}
}
 
Declaring using-namespace-
directives
 Effectively brings names back into scope
using VendorA.SuiteB;
class Application
{
static void Main( )
{
Widget w = new Widget( );
}
}
namespace VendorA.SuiteB
{
public class Widget { ... }
}
Declaring using-alias-directives
 Creates an alias for a deeply nested namespace or type
using Widget = VendorA.SuiteB.Widget;
class Application
{
static void Main( )
{
Widget w = new Widget( );
}
}
namespace VendorA.SuiteB
{
public class Widget { ... }
}
Guidelines for Naming
Namespaces
 Use PascalCasing to separate logical components
 Example: VendorA.SuiteB
 Prefix namespace names with a company name or well-
established brand
 Example: Microsoft.Office
 Use plural names when appropriate
 Example: System.Collections
 Avoid name clashes between namespaces and classes
Using Modules and Assemblies
 Creating Modules
 Using Assemblies
 Creating Assemblies
 Comparing Namespaces to Assemblies
 Using Versioning
Using Modules
 .cs files can be compiled into a (.netmodule) managed
module
csc /target:module Bank.cs
Using Assemblies
 Group of collaborating classes
 Reusable, versionable, and secure deployment unit
 Physical access control at assembly level
 Internal
an assembly
of four classes
public
internal
private
Creating Assemblies
 Creating a single-file assembly
 Creating multifile assembly
csc /target:library /out:Bank.dll
Bank.cs Account.cs
csc /t:library /addmodule:Account.netmodule
/out:Bank.dll Bank.cs
Comparing Namespaces to
Assemblies
 Namespace: logical naming mechanism
 Classes from one namespace can reside in
many assemblies
 Classes from many namespaces can reside in
one assembly
 Assembly: physical grouping mechanism
 Assembly MSIL and manifest are contained directly
 Assembly modules and resources can be external links
Using Versioning
 Each assembly has a version number as part of its
identity
 This version number is physically represented as a four-
part number with the following format:
<major version>.<minor version>.<build
number>.<revision>
Review
 Using Internal Classes, Methods, and Data
 Using Aggregation
 Using Namespaces
 Using Modules and Assemblies

More Related Content

What's hot (20)

Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
 
class and objects
class and objectsclass and objects
class and objects
 
Objects and classes in Visual Basic
Objects and classes in Visual BasicObjects and classes in Visual Basic
Objects and classes in Visual Basic
 
Introduction to c ++ part -2
Introduction to c ++   part -2Introduction to c ++   part -2
Introduction to c ++ part -2
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
Reflection in C Sharp
Reflection in C SharpReflection in C Sharp
Reflection in C Sharp
 
Reflection power pointpresentation ppt
Reflection power pointpresentation pptReflection power pointpresentation ppt
Reflection power pointpresentation ppt
 
Serialization in .NET
Serialization in .NETSerialization in .NET
Serialization in .NET
 
.NET Reflection
.NET Reflection.NET Reflection
.NET Reflection
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in java
 
Generics collections
Generics collectionsGenerics collections
Generics collections
 
Constructor
ConstructorConstructor
Constructor
 
C# Generics
C# GenericsC# Generics
C# Generics
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Constructors destructors
Constructors destructorsConstructors destructors
Constructors destructors
 
Hibernate
HibernateHibernate
Hibernate
 
04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructor
 
vb.net Constructor and destructor
vb.net Constructor and destructorvb.net Constructor and destructor
vb.net Constructor and destructor
 

Similar to Module 12 aggregation, namespaces, and advanced scope

Is2215 lecture4 student (1)
Is2215 lecture4 student (1)Is2215 lecture4 student (1)
Is2215 lecture4 student (1)dannygriff1
 
Creational pattern 2
Creational pattern 2Creational pattern 2
Creational pattern 2Naga Muruga
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805LearningTech
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805LearningTech
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)Jay Patel
 
Xamarin: Namespace and Classes
Xamarin: Namespace and ClassesXamarin: Namespace and Classes
Xamarin: Namespace and ClassesEng Teong Cheah
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesDurgesh Singh
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .NetGreg Sohl
 
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Alena Holligan
 

Similar to Module 12 aggregation, namespaces, and advanced scope (20)

Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
 
Ch03
Ch03Ch03
Ch03
 
Ch03
Ch03Ch03
Ch03
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Creational pattern 2
Creational pattern 2Creational pattern 2
Creational pattern 2
 
Java Reflection Concept and Working
Java Reflection Concept and WorkingJava Reflection Concept and Working
Java Reflection Concept and Working
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Xamarin: Namespace and Classes
Xamarin: Namespace and ClassesXamarin: Namespace and Classes
Xamarin: Namespace and Classes
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Intake 37 4
Intake 37 4Intake 37 4
Intake 37 4
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modules
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
Beyond pageobjects
Beyond pageobjectsBeyond pageobjects
Beyond pageobjects
 
C#.net Evolution part 1
C#.net Evolution part 1C#.net Evolution part 1
C#.net Evolution part 1
 
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017
 
2310 b 03
2310 b 032310 b 03
2310 b 03
 
Effective PHP. Part 4
Effective PHP. Part 4Effective PHP. Part 4
Effective PHP. Part 4
 

More from Prem Kumar Badri

Module 14 properties and indexers
Module 14 properties and indexersModule 14 properties and indexers
Module 14 properties and indexersPrem Kumar Badri
 
Module 10 : creating and destroying objects
Module 10 : creating and destroying objectsModule 10 : creating and destroying objects
Module 10 : creating and destroying objectsPrem Kumar Badri
 
Module 9 : using reference type variables
Module 9 : using reference type variablesModule 9 : using reference type variables
Module 9 : using reference type variablesPrem Kumar Badri
 
Module 8 : Implementing collections and generics
Module 8 : Implementing collections and genericsModule 8 : Implementing collections and generics
Module 8 : Implementing collections and genericsPrem Kumar Badri
 
Module 6 : Essentials of Object Oriented Programming
Module 6 : Essentials of Object Oriented ProgrammingModule 6 : Essentials of Object Oriented Programming
Module 6 : Essentials of Object Oriented ProgrammingPrem Kumar Badri
 
Module 5 : Statements & Exceptions
Module 5 : Statements & ExceptionsModule 5 : Statements & Exceptions
Module 5 : Statements & ExceptionsPrem Kumar Badri
 
Module 4 : methods & parameters
Module 4 : methods & parametersModule 4 : methods & parameters
Module 4 : methods & parametersPrem Kumar Badri
 
Module 3 : using value type variables
Module 3 : using value type variablesModule 3 : using value type variables
Module 3 : using value type variablesPrem Kumar Badri
 
Module 1 : Overview of the Microsoft .NET Platform
Module 1 : Overview of the Microsoft .NET PlatformModule 1 : Overview of the Microsoft .NET Platform
Module 1 : Overview of the Microsoft .NET PlatformPrem Kumar Badri
 
C# Non generics collection
C# Non generics collectionC# Non generics collection
C# Non generics collectionPrem Kumar Badri
 
C# Filtering in generic collections
C# Filtering in generic collectionsC# Filtering in generic collections
C# Filtering in generic collectionsPrem Kumar Badri
 

More from Prem Kumar Badri (20)

Module 14 properties and indexers
Module 14 properties and indexersModule 14 properties and indexers
Module 14 properties and indexers
 
Module 11 : Inheritance
Module 11 : InheritanceModule 11 : Inheritance
Module 11 : Inheritance
 
Module 10 : creating and destroying objects
Module 10 : creating and destroying objectsModule 10 : creating and destroying objects
Module 10 : creating and destroying objects
 
Module 9 : using reference type variables
Module 9 : using reference type variablesModule 9 : using reference type variables
Module 9 : using reference type variables
 
Module 8 : Implementing collections and generics
Module 8 : Implementing collections and genericsModule 8 : Implementing collections and generics
Module 8 : Implementing collections and generics
 
Module 7 : Arrays
Module 7 : ArraysModule 7 : Arrays
Module 7 : Arrays
 
Module 6 : Essentials of Object Oriented Programming
Module 6 : Essentials of Object Oriented ProgrammingModule 6 : Essentials of Object Oriented Programming
Module 6 : Essentials of Object Oriented Programming
 
Module 5 : Statements & Exceptions
Module 5 : Statements & ExceptionsModule 5 : Statements & Exceptions
Module 5 : Statements & Exceptions
 
Module 4 : methods & parameters
Module 4 : methods & parametersModule 4 : methods & parameters
Module 4 : methods & parameters
 
Module 3 : using value type variables
Module 3 : using value type variablesModule 3 : using value type variables
Module 3 : using value type variables
 
Module 2: Overview of c#
Module 2:  Overview of c#Module 2:  Overview of c#
Module 2: Overview of c#
 
Module 1 : Overview of the Microsoft .NET Platform
Module 1 : Overview of the Microsoft .NET PlatformModule 1 : Overview of the Microsoft .NET Platform
Module 1 : Overview of the Microsoft .NET Platform
 
C# Non generics collection
C# Non generics collectionC# Non generics collection
C# Non generics collection
 
C# Multi threading
C# Multi threadingC# Multi threading
C# Multi threading
 
C# Method overloading
C# Method overloadingC# Method overloading
C# Method overloading
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
 
C# Generic collections
C# Generic collectionsC# Generic collections
C# Generic collections
 
C# Global Assembly Cache
C# Global Assembly CacheC# Global Assembly Cache
C# Global Assembly Cache
 
C# Filtering in generic collections
C# Filtering in generic collectionsC# Filtering in generic collections
C# Filtering in generic collections
 
C# File IO Operations
C# File IO OperationsC# File IO Operations
C# File IO Operations
 

Recently uploaded

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Module 12 aggregation, namespaces, and advanced scope

  • 2. Overview  Using Internal Classes, Methods, and Data  Using Aggregation  Using Namespaces  Using Modules and Assemblies
  • 3. Using Internal Classes, Methods, and Data  Why Use Internal Access?  Internal Access  Syntax  Internal Access Example
  • 4. Why Use Internal Access?  Small objects are not very useful on their own  Objects need to collaborate to form larger objects  Access beyond the individual object is required public internal private
  • 5. Internal Access  Comparing access levels  Public access is logical  Private access is logical  Internal access is physical internal
  • 6. Syntax internal class <outername> { internal class <nestedname> { ... } internal <type> field; internal <type> Method( ) { ... } protected internal class <nestedname> { ... } protected internal <type> field; protected internal <type> Method( ) { ... } } protected internal means protected or internal
  • 7. Internal Access Example public interface IBankAccount { ... } internal abstract class CommonBankAccount { ... } internal class DepositAccount: CommonBankAccount, IBankAccount { ... } public class Bank { public IBankAccount OpenAccount( ) { return new DepositAccount( ); } }
  • 8. Using Aggregation  Objects Within Objects  Comparing Aggregation to Inheritance  Factories  Example Factory
  • 9. Objects Within Objects  Complex objects are built from simpler objects  Simpler objects are parts of complex whole objects  This is called aggregation CarWhole Part EngineChassis Wheel 1 41
  • 10. Comparing Aggregation to Inheritance  Aggregation  Specifies an object relationship  A weak whole-to-part dependency  Dynamically flexible  Inheritance  Specifies a class relationship  A strong derived-to-base dependency  Statically inflexible Part Whole Base Derived
  • 11. Factories  Creation is often complex and restricted  Many objects are made only in specialist factories  The factory encapsulates the complex creation  Factories are useful patterns when modelling software
  • 12. Factory Example public class Bank { public BankAccount OpenAccount( ) { BankAccount opened = new BankAccount( ); accounts[opened.Number( )] = opened; return opened; } private Hashtable accounts = new Hashtable( ); } public class BankAccount { internal BankAccount( ) { ... } public long Number( ) { ... } public void Deposit(decimal amount) { ... } }
  • 13. Using Namespaces  Scope Revisited  Resolving Name Clashes  Declaring Namespaces  Fully Qualified Names  Declaring using-namespace-directives  Declaring using-alias-directives  Guidelines for Naming Namespaces
  • 14. Scope Revisited  The scope of a name is the region of program text in which you can refer to the name without qualification public class Bank { public class Account { public void Deposit(decimal amount) { balance += amount; } private decimal balance; } public Account OpenAccount( ) { ... } }
  • 15. Resolving Name Clashes  Consider a large project that uses thousands of classes  What if two classes have the same name?  Do not add prefixes to all class names // From Vendor A public class Widget public class VendorAWidget { ... } { ... } // From Vendor B public class Widget public class VendorBWidget { ... } { ... } 
  • 16. Declaring Namespaces namespace VendorA { public class Widget { ... } } namespace VendorB { public class Widget { ... } } namespace Microsoft { namespace Office { ... } } namespace Microsoft.Office { } shorthand
  • 17. Fully Qualified Names  A fully qualified class name includes its namespace  Unqualified class names can only be used in scope namespace VendorA { public class Widget { ... } ... } class Application { static void Main( ) { Widget w = new Widget( ); VendorA.Widget w = new VendorA.Widget( ); } }  
  • 18. Declaring using-namespace- directives  Effectively brings names back into scope using VendorA.SuiteB; class Application { static void Main( ) { Widget w = new Widget( ); } } namespace VendorA.SuiteB { public class Widget { ... } }
  • 19. Declaring using-alias-directives  Creates an alias for a deeply nested namespace or type using Widget = VendorA.SuiteB.Widget; class Application { static void Main( ) { Widget w = new Widget( ); } } namespace VendorA.SuiteB { public class Widget { ... } }
  • 20. Guidelines for Naming Namespaces  Use PascalCasing to separate logical components  Example: VendorA.SuiteB  Prefix namespace names with a company name or well- established brand  Example: Microsoft.Office  Use plural names when appropriate  Example: System.Collections  Avoid name clashes between namespaces and classes
  • 21. Using Modules and Assemblies  Creating Modules  Using Assemblies  Creating Assemblies  Comparing Namespaces to Assemblies  Using Versioning
  • 22. Using Modules  .cs files can be compiled into a (.netmodule) managed module csc /target:module Bank.cs
  • 23. Using Assemblies  Group of collaborating classes  Reusable, versionable, and secure deployment unit  Physical access control at assembly level  Internal an assembly of four classes public internal private
  • 24. Creating Assemblies  Creating a single-file assembly  Creating multifile assembly csc /target:library /out:Bank.dll Bank.cs Account.cs csc /t:library /addmodule:Account.netmodule /out:Bank.dll Bank.cs
  • 25. Comparing Namespaces to Assemblies  Namespace: logical naming mechanism  Classes from one namespace can reside in many assemblies  Classes from many namespaces can reside in one assembly  Assembly: physical grouping mechanism  Assembly MSIL and manifest are contained directly  Assembly modules and resources can be external links
  • 26. Using Versioning  Each assembly has a version number as part of its identity  This version number is physically represented as a four- part number with the following format: <major version>.<minor version>.<build number>.<revision>
  • 27. Review  Using Internal Classes, Methods, and Data  Using Aggregation  Using Namespaces  Using Modules and Assemblies