File tree 7 files changed +88
-59
lines changed 7 files changed +88
-59
lines changed Original file line number Diff line number Diff line change 1
- using System ;
2
-
3
- public abstract class AbstractCustomer {
4
- protected string title ;
5
-
6
- public abstract string GetTitle ( ) ;
1
+ using System ;
2
+
3
+ namespace NullObject {
4
+
5
+ public abstract class AbstractBook {
6
+
7
+ protected string title ;
8
+
9
+ public abstract string GetTitle ( ) ;
10
+
11
+ }
12
+
7
13
}
Original file line number Diff line number Diff line change 1
- using System ;
2
-
3
- public class Book : AbstractCustomer {
4
-
5
- public Book ( String title ) {
6
- this . title = title ;
7
- }
8
-
9
- public override string GetTitle ( ) {
10
- return title ;
11
- }
12
- }
1
+ using System ;
2
+
3
+ namespace NullObject {
4
+
5
+ public class Book : AbstractBook {
6
+
7
+ public Book ( string title ) {
8
+ this . title = title ;
9
+ }
10
+
11
+ public override string GetTitle ( ) {
12
+ return title ;
13
+ }
14
+
15
+ }
16
+
17
+ }
Original file line number Diff line number Diff line change 1
- using System ;
2
-
3
- public class BookFactory {
4
-
5
- public static string [ ] books = { "Book1" , "Book2" , "Book3" } ;
6
-
7
- public static AbstractCustomer GetBook ( string title ) {
8
- for ( int i = 0 ; i < books . Length ; i ++ )
9
- if ( books [ i ] == title )
10
- return new Book ( title ) ;
11
- return new NullBook ( ) ;
12
- }
13
-
14
- }
1
+ using System ;
2
+
3
+ namespace NullObject {
4
+
5
+ public class BookFactory {
6
+
7
+ public static string [ ] books = { "Book1" , "Book2" , "Book3" } ;
8
+
9
+ public static AbstractBook GetBook ( string title ) {
10
+ for ( int i = 0 ; i < books . Length ; i ++ ) {
11
+ if ( books [ i ] == title ) {
12
+ return new Book ( title ) ;
13
+ }
14
+ }
15
+ return new NullBook ( ) ;
16
+ }
17
+
18
+ }
19
+
20
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
3
- class NullBook : AbstractCustomer {
4
-
5
- public override string GetTitle ( ) {
6
- return "Not avaible in Customer Database" ;
7
- }
8
-
3
+ namespace NullObject {
4
+
5
+ class NullBook : AbstractBook {
6
+
7
+ public override string GetTitle ( ) {
8
+ return "Not avaible in Customer Database" ;
9
+ }
10
+
11
+ }
12
+
9
13
}
Original file line number Diff line number Diff line change 32
32
<Reference Include =" System" />
33
33
</ItemGroup >
34
34
<ItemGroup >
35
- <Compile Include =" Program.cs" />
36
35
<Compile Include =" Properties\AssemblyInfo.cs" />
36
+ <Compile Include =" AbstractBook.cs" />
37
+ <Compile Include =" Book.cs" />
38
+ <Compile Include =" BookFactory.cs" />
39
+ <Compile Include =" Program.cs" />
40
+ <Compile Include =" NullBook.cs" />
37
41
</ItemGroup >
38
42
<Import Project =" $(MSBuildBinPath)\Microsoft.CSharp.targets" />
39
43
</Project >
Original file line number Diff line number Diff line change
1
+ using System ;
2
+
3
+ namespace NullObject {
4
+
5
+ public class Program {
6
+
7
+ static void Main ( string [ ] args ) {
8
+
9
+ AbstractBook c1 = BookFactory . GetBook ( "Book1" ) ;
10
+ AbstractBook c2 = BookFactory . GetBook ( "Book5" ) ;
11
+ AbstractBook c3 = BookFactory . GetBook ( "Book2" ) ;
12
+ AbstractBook c4 = BookFactory . GetBook ( "Book3" ) ;
13
+ AbstractBook c5 = BookFactory . GetBook ( "Book9" ) ;
14
+
15
+ Console . WriteLine ( c1 . GetTitle ( ) ) ;
16
+ Console . WriteLine ( c2 . GetTitle ( ) ) ;
17
+ Console . WriteLine ( c3 . GetTitle ( ) ) ;
18
+ Console . WriteLine ( c4 . GetTitle ( ) ) ;
19
+ Console . WriteLine ( c5 . GetTitle ( ) ) ;
20
+ }
21
+
22
+ }
23
+
24
+ }
You can’t perform that action at this time.
0 commit comments