Foundations of object-oriented programming using .net 2.0 patterns download




















Some classes define multiple constructors, and this syntax enables you to pick which base class constructor you call. Once you've updated the constructors, you can develop the code for each of the derived classes. The requirements for the new classes can be stated as follows:. You can see that all three of these account types have an action that takes places at the end of each month. However, each account type does different tasks. You use polymorphism to implement this code.

Create a single virtual method in the BankAccount class:. The preceding code shows how you use the virtual keyword to declare a method in the base class that a derived class may provide a different implementation for. A virtual method is a method where any derived class may choose to reimplement.

The derived classes use the override keyword to define the new implementation. Typically you refer to this as "overriding the base class implementation". The virtual keyword specifies that derived classes may override the behavior. You can also declare abstract methods where derived classes must override the behavior.

The base class does not provide an implementation for an abstract method. Next, you need to define the implementation for two of the new classes you've created. Start with the InterestEarningAccount :. Add the following code to the LineOfCreditAccount. The code negates the balance to compute a positive interest charge that is withdrawn from the account:. The GiftCardAccount class needs two changes to implement its month-end functionality.

First, modify the constructor to include an optional amount to add each month:. The constructor provides a default value for the monthlyDeposit value so callers can omit a 0 for no monthly deposit. Next, override the PerformMonthEndTransactions method to add the monthly deposit, if it was set to a non-zero value in the constructor:.

The override applies the monthly deposit set in the constructor. Verify the results. Now, add a similar set of test code for the LineOfCreditAccount :.

When you add the preceding code and run the program, you'll see something like the following error:. The actual output includes the full path to the folder with the project. The folder names were omitted for brevity. Also, depending on your code format, the line numbers may be slightly different. This code fails because the BankAccount assumes that the initial balance must be greater than 0. Another assumption baked into the BankAccount class is that the balance can't go negative.

Instead, any withdrawal that overdraws the account is rejected. Both of those assumptions need to change. The line of credit account starts at 0, and generally will have a negative balance. Also, if a customer borrows too much money, they incur a fee. The transaction is accepted, it just costs more. The first rule can be implemented by adding an optional argument to the BankAccount constructor that specifies the minimum balance. The default is 0. The second rule requires a mechanism that enables derived classes to modify the default algorithm.

In a sense, the base class "asks" the derived type what should happen when there's an overdraft. Advanced C Language Features LINQ to Objects Understanding Object Lifetime 5. Programming with. NET Assemblies Building and Configuring Class Libraries Dynamic Types and the Dynamic Language Runtime Processes, AppDomains, and Object Contexts Introducing the.

Multithreaded, Parallel, and Async Programming Data Access with ADO. NET Introducing Entity Framework 6 Introducing Windows Communication Foundation 7. Windows Presentation Foundation Introducing ASP. NET Core Introducing Entity Framework Core Product information Title: Pro C 7: With. NET Framework classes that implement graphics.

It covers all of the classes, methods, and techniques needed to create, manipulate, and display precise graphics in a form, a page being sent to a printer, or an image. On this foundation, the second section describes how to design and build effective custom controls for use in a business environment. Topics covered include building composite controls, implementing keyboard navigation, and enhancing design-time support. NET to build custom controls that can provide reusable, GUI components for web projects, and to deliver customized graphics over the Internet.

Skip to main content Skip to table of contents. Advertisement Hide. This service is more advanced with JavaScript available. Authors Eric White. Front Matter Pages i-xxvi.



0コメント

  • 1000 / 1000