寻麻疹用什么药好:c# 里关于Factory 模式的问题!!帮忙看一下

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 07:43:23
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 public interface IAccount
6 {
7 long Number
8 {
9 get;
10 }
11 decimal Balance
12 {
13 get;
14 }
15 void Deposit(decimal amount);
16 void Withdraw(decimal amount);
17 }
18
19 public class Bank
20 {
21 public IAccount OpenAccount()
22 {
23 IAccount acc = new Account();
24 accounts[acc.Number]=acc;
25 return acc;
26 }
27 private readonly Hashtable accounts = new Hashtable();
28 private sealed class Account : IAccount
29 {
30 public long Number
31 {
32 get
33 {
34 return number;
35 }
36 }
37 public decimal Balance
38 {
39 get
40 {
41 return Balance;
42 }
43 }
44 public void Deposit(decimal amount)
45 {
46 balance += amount;
47 }
48 public void Withdraw(decimal amount)
49 {
50 balance -= amount;
51 }
52 private decimal balance = 0;
53 private readonly long number = nextNumber++;
54 private static long nextNumber = 123;
55 }
56 }
57
58 class Test
59 {
60 static void Main()
61 {
62 Bank bank = new Bank();
63 IAccount account=bank.OpenAccount();
64 account=bank.OpenAccount();
65 account.Deposit(100.00M);
66 account.Withdraw(40.00M);
67 Console.WriteLine("Account {0} has $ {1}",account.Number,account.Balance);
68
69 }
70 }

问题:

1。 第21 行 public IAccount OpenAccount() 这个不是一个方法吗,那他的返回类型怎么是接口名称,要是返回接口怎么不用interface .(IAccount 在着到底是什么意思,怎么用),最后告诉我这个方法在这的意义就是干什么用的把??

2。 还有第63,64行那两句有什么用,存在的意义,不要可以吗??

3。顺便告诉我一下这是欠缺哪部分知识。

谢谢了