A BankAccount class that uses composition in Visual Basic .NET

Encoding QR-Code in Visual Basic .NET A BankAccount class that uses composition
A BankAccount class that uses composition
Drawing QR In VB.NET
Using Barcode generation for .NET Control to generate, create QR image in VS .NET applications.
The simple 1:1 composition allows us to use a Person object as a member eld of a BankAccount object In code, it would appear something like Listing 103
Creating Bar Code In Visual Basic .NET
Using Barcode generation for VS .NET Control to generate, create barcode image in .NET applications.
Public Class Person Public Name As String Public Address As String 'etc End Class Public Class CustAccount Private AccountNumber As Long Private Customer As Person Public Sub New(ByVal Number As Long, _ ByVal Name As String, _ ByVal Address As String) AccountNumber = Number Customer = New Person() CustomerName = Name CustomerAddress = Address 'etc End Sub 'More methods End Class Listing 103: Code for the composition structure
QR Code 2d Barcode Printer In Visual C#.NET
Using Barcode generation for .NET framework Control to generate, create QR Code image in .NET applications.
103 Choices in Modelling Object Relationships
Generating QR Code JIS X 0510 In Visual Studio .NET
Using Barcode encoder for ASP.NET Control to generate, create QR Code JIS X 0510 image in ASP.NET applications.
BankAccount re-modelled for joint accounts
Encoding QR Code In .NET
Using Barcode drawer for .NET framework Control to generate, create QR image in VS .NET applications.
If we were now to go on to de ne a JointAccount class, the temptation would be to say that since this is a specialized form of account, we should inherit BankAccount and add in the additional member However, inheritance is computationally costly in a number of ways, and if we can legitimately avoid using it our program will be more ef cient The question to ask is whether any of the operations for a BankAccount will need to be signi cantly changed for a JointAccount I would answer no to this question, since all of the main operations of an account could deal with either one or two account signatories without any need for inheritance Instead, the composition relationship could be extended as in Figure 106 Now the code for BankAccount will have to become a little more complex, since we will need to provide a method to optionally add in a second customer, and we will also have to check for a second customer when generating a statement However, we have saved having to use inheritance, a bene t in itself, and more importantly, we have made it possible to convert any BankAccount into a joint account by simply adding a second customer at any time Using inheritance, converting from a standard account to a joint account would have involved a nightmare of code to create the new type of account, copy all of the existing data over to it (including all of the transactions), add in the second customer s information and then destroy the original account Instead we have replaced an inheritance relationship with a much simpler (and computationally cheaper) composition one Of course if an unlimited number of signatories were to be possible, we would need to deal with an aggregation of account names, and this might make it worth creating a new class that inherits from BankAccount In designing class models, there are always likely to be possible alternative implementations of the ideal situation The best choice of data structure (eg between an ArrayList, a HashTable and a Dictionary) is not always obvious Similarly, the choice between a simple composition (using reference variables in a class de nition) and an aggregation (using one of the Collection class objects) is usually not clear cut While the best solution is often to choose the most simple and direct approach (eg having the space for two Customer objects in a bank account), sometimes this approach can impose a limitation on a class design that will only be apparent later Software design is as much an art as a science, and while learning to use the facilities of a programming language is a relatively simple matter, learning how and when these facilities should be employed is much more dif cult and comes only with experience Examining program code, whether from books like this, magazines, journals or on-line is valuable; working with code by copying and
Barcode Maker In Visual Basic .NET
Using Barcode creation for Visual Studio .NET Control to generate, create bar code image in .NET framework applications.
10 n Object Modelling
Creating Barcode In VB.NET
Using Barcode creation for .NET Control to generate, create bar code image in .NET framework applications.
modifying is much more valuable Even then, experienced programmers frequently get it wrong Very few programmers invent a technique Most learn their craft by emulating what other programmers have done and developing a mental catalogue of programming examples and techniques We will return to this theme when we go on to look at Software Patterns later in this chapter
Code-39 Maker In VB.NET
Using Barcode creator for Visual Studio .NET Control to generate, create Code 3/9 image in .NET applications.
Code 128B Maker In Visual Basic .NET
Using Barcode generator for .NET Control to generate, create USS Code 128 image in VS .NET applications.
Encoding Barcode In Visual Studio .NET
Using Barcode creator for .NET Control to generate, create barcode image in VS .NET applications.
Encoding DataMatrix In Java
Using Barcode creation for Java Control to generate, create Data Matrix 2d barcode image in Java applications.
Bar Code Reader In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
GS1 - 12 Generator In VS .NET
Using Barcode generator for ASP.NET Control to generate, create UCC - 12 image in ASP.NET applications.
Data Matrix ECC200 Drawer In .NET
Using Barcode printer for ASP.NET Control to generate, create Data Matrix image in ASP.NET applications.