27.07.2013 Views

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

15 <strong>Model</strong>ing Objects<br />

In the previous chapters we showed how the state variables of a model program<br />

can be expressed as the fields of classes declared in a given C# namespace. Up<br />

to this point in our presentation such fields have all been global, that is, declared<br />

with the C# static keyword. In this chapter, we show how model programs can be<br />

written to use instance-based fields as state variables. This is sometimes called an<br />

object-oriented style of modeling.<br />

<strong>We</strong> will also show how instances of C# classes (“objects”) be thought of as abstract<br />

identifiers. Abstract values like object IDs may be considered to be an equivalence<br />

class when exploring the model. Ignoring states that are structurally identical to<br />

a previous state except for their choice of object IDs can make exploration more<br />

efficient.<br />

There is nothing fundamental about the object-oriented style of modeling; equivalent<br />

behavior can also be expressed using the structure-based style presented in<br />

Chapter 10. The motivation for objects is primarily convenience. Many programmers<br />

are familiar with the object-oriented style, and writing a model in this style<br />

can sometimes improve its readability.<br />

15.1 Instance variables as field maps<br />

Structures like maps can be used to encode state that occurs “per-instance.” For<br />

example, we could use maps to model a payroll system:<br />

namespace Payroll1<br />

{<br />

class Employee : CompoundValue<br />

{<br />

public readonly int id;<br />

public Employee(int id) { this.id = id; }<br />

}<br />

more free ebooks download links at:<br />

http://www.ebook-x.com<br />

247

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!