During this lab session:
This activity helps the student develop the following skills, values and attitudes: ability to analyze and synthesize, capacity for identifying and solving problems, and efficient use of computer systems.
This lab is based on chapters 4 and 5 of [FREEMAN]. It can be developed individually or in pairs.
The following ZIP file contains the files and folders you'll be needing for this lab: abstractfactory_singleton.zip. Any new files you create must go inside the corresponding folder.
Carefully study the following NUnit text fixture:
namespace Headfirst.Factory.Pizzaaf {
using NUnit.Framework;
using System;
[TestFixture]
public class TestAbstractFactory {
static readonly string EOL = Environment.NewLine;
PizzaStore store;
[SetUp]
public void Init() {
store = new TecPizzeria();
}
[Test]
public void TestVeggie() {
Pizza p = store.OrderPizza("veggie");
Assert.AreEqual("---- Tec Vegetarian Pizza ----" + EOL
+ "Yummy stuffed crust style dough" + EOL
+ "Tomato sauce with plum tomatoes" + EOL
+ "Shredded Parmesan" + EOL
+ "Jalapeno, Black Olives, Onion, Red Pepper, Mushrooms" + EOL,
p.ToString());
}
[Test]
public void TestPepperoni() {
Pizza p = store.OrderPizza("pepperoni");
Assert.AreEqual("---- Tec Pepperoni Pizza ----" + EOL
+ "Yummy stuffed crust style dough" + EOL
+ "Tomato sauce with plum tomatoes" + EOL
+ "Shredded Parmesan" + EOL
+ "Jalapeno, Black Olives, Onion, Red Pepper, Mushrooms" + EOL
+ "Sliced Pepperoni" + EOL,
p.ToString());
}
[Test]
public void TestCheese() {
Pizza p = store.OrderPizza("cheese");
Assert.AreEqual("---- Tec Cheese Pizza ----" + EOL
+ "Yummy stuffed crust style dough" + EOL
+ "Tomato sauce with plum tomatoes" + EOL
+ "Shredded Parmesan" + EOL,
p.ToString());
}
[Test]
public void TestClam() {
Pizza p = store.OrderPizza("clam");
Assert.AreEqual("---- Tec Clam Pizza ----" + EOL
+ "Yummy stuffed crust style dough" + EOL
+ "Tomato sauce with plum tomatoes" + EOL
+ "Shredded Parmesan" + EOL
+ "Fresh Clams from Long Island Sound" + EOL,
p.ToString());
}
}
}
Write the following new classes:
Headfirst.Factory.Pizzaaf.TecPizzaIngredientFactoryHeadfirst.Factory.Pizzaaf.TecPizzeriaMake sure that they behave exactly as expected by the unit tests. Do not modify any other part of the code.
Read sections 5.3.3 and 5.3.4 of [BISHOP]. Using the provided design and implementation guidelines, convert the following class into a singleton. The modified class must be thread-safe and use lazy instantiation.
namespace Headfirst.Singleton {
public class Tigger {
public override string ToString() {
return "I'm the only one!";
}
public string Roar() {
return "Grrr!";
}
}
}
Check your solution using the following test case:
namespace Headfirst.Singleton {
using NUnit.Framework;
[TestFixture]
public class TestSingleton {
[Test]
public void TestTigger() {
Tigger t = Tigger.UniqueInstance;
Assert.AreSame(Tigger.UniqueInstance, t);
Assert.AreEqual("I'm the only one!", t.ToString());
Assert.AreEqual("Grrr!", t.Roar());
}
}
}
To hand in your lab work, follow these instructions:
readme.txt text file that includes the name
and student ID of the authors. Copy this file to both
chapter04 and chapter05 folders.
chapter04 and chapter05 directories.
Call this file chapter04_05.zip.
This activity will be evaluated using the following criteria:
| 100 | The code works as requested. |
|---|---|
| 60-90 | The code works, but has some flaws. |
| 20-50 | The code doesn't work, but it seams that some amount of time was spent on it. |
| DA | The program was plagiarized. |