Source code using System; using System.Collections.Generic; namespace Observer_Pattern_Weather_Station { publicinterfaceISubject { // the registering of the observer void registerObserver(IObserver o); // the deleting of the observer void removeObserver(IObserver o); // it is called to notify the observers // when the Subject’s state has changed void notifyObservers(); } publicinterfaceIObserver { // the values that the observers get from the Subject, push-solution void update(float temp, float humidity, float pressure); } publicinterfaceIDisplayElement { // we call it when we would like to show the display element void display(); } // the Subject interface is being implemented publicclassWeatherData : ISubject { // we add a list that contains the observers privateList<IObserver> observers; privatefloat temperature; privatefloat humidity; privatefloat pressure; public WeatherData() { // the list containing the observers is being created observers = newList<IObserver>(); } publicvoid registerObserver(IObserver o) { // when an observer registers in, we simply add it to the list observers.Add(o); } publicvoid removeObserver(IObserver o) { // when an observer would like to register out, it’s simply deleted from the list int i = observers.IndexOf(o); if (i >= 0) { observers.Remove(o); }
Modules. For example, the often-used unit-test is the structure test of methods. The levels of testing The levels of testing are the following: component test, integration test, system test, acceptance test. The component test only tests one component of the system in itself. The integration test tests the cooperation of two or more components. The system test tests the whole system, all the components together. The first three test levels together are called developer tests, as they are done by the developer company’s employees. During the acceptance test, the users test the finished system. They are usually in the same time order. The component test tests the independent parts of the system and the source code is usually known (white-box testing). Common types: unit-test, module test. The unit-test, or unity test, tests the methods. We know the method’s return value (or side effect) for given parameters. The unit-test examines if the return values matches the expected. If yes, the test is successful, in other cases, it is a failure. It is an expectation that the unit-test itself can’t have side effects. Unit-testing is supported by nearly all modern programming environments (integrated development environment, IDE), so it’s quite easy to write such tests. Their significance is their running is supported to, so after a change, we can simply run all the unit-tests and ensure that the change didn’t cause any errors. This is called the regression test. The module test usually tests the non-functional attribute of the module, for example it’s speed, the possibility of memory leak or the presence of bottlenecks. During the integration test, the interfaces between the components, the interface between the operating system and the system and interfaces towards other systems are being tested. The most well-known types of integration tests: Component-Component integration test: the test of interaction between components after the component test. System – System Integration test: the test of interaction between the system and other systems after the system test.