Notes On Software Engineering

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Software Engineering

Overview of reasons for and goals of software engineering


1. The reason is to adapt engineering practices to software development.
2. The goal of the specialty is improved software, which is defined by maintainability, efficiency,
correctness, and reusability. The program is for students who want to learn the theory and
practice of Software Engineering, knowledge engineering and software project management.
o Techniques that work for small programs don’t scale
o Big systems live on beyond original author(s)
o Most effort expended after first release
o Requirements change rapidly
o User expectations increase rapidly
o Most software late, expensive, buggy or inadequate
o Last minute testing can’t ensure quality

Idealized software life cycle


1. Analysis of requirements (14-22%)
2. Design (16% - 21%)
3. Implementation (30% – 39%)
4. Testing (2%-37%)
5. Maintenance

Version control
For tracking and controlling changes to a project's files, in particular to source code, documentation, and
web pages.

The core of version control is change management: identifying each discrete change made to the
project's files, annotating each change with metadata like the change's date and author, and then
replaying these facts to whoever asks, in whatever way they ask.

Vocabulary
1. Commit - To make a change to the project; more formally, to store a change in the
version control database in such a way that it can be incorporated into future releases
of the project.

2. Log  message - A bit of commentary attached to each commit, describing the nature and
purpose of the commit.

3. Update – The act of asking that others' changes (commits) be incorporated into your
local copy of the project; that is, to bring your copy "up-to-date.
4. Repository - A database in which changes are stored\

5. Checkout - The process of obtaining a copy of the project from a repository.

6. Working copy - A developer's private directory tree that contains the project's source
code files, and possibly its web pages or other documents.
7. Revision, change, changes set - One specific incarnation of a particular file or directory.
For example, if the project starts out with revision 6 of file F, and then someone
commits a change to F, this produces revision 7 of F. Some systems also use "revision",
"change", or "change set" to refer to a set of changes committed together as one
conceptual unit.

8. Diff - A textual representation of a change. A diff shows which lines were changed and
how, plus a few lines of surrounding context on either side.

9. Tag - A label for a particular collection of files at specified revisions.

10. Branches, development is still considered to be happening on the "main branch", also
known as the "main line" or "trunk".

11. Merge (a.k.a. port) - To move a change from one branch to another. This includes
merging from the main trunk to some other branch, or vice versa.

12. Conflict - What happens when two people try to make different changes to the same
place in the code. All version control systems automatically detect conflicts, and notify
at least one of the humans involved that their changes conflict with someone else's. It is
then up to that human to resolve the conflict, and to communicate that resolution to
the version control system.

13. Lock - A way to declare an exclusive intent to change a particular file or directory.

14. Branch - A copy of the project, under version control but isolated, so that changes made
to the branch don't affect the rest of the project, and vice versa, except when changes
are deliberately "merged" from one side to the other (see below). Branches are also
known as "lines of development". Even when a project has no explicit

Unit Testing
1. Testing a unit of code in isolation
2. A Unit is the smallest piece of code that can be tested in isolation
a. Smallest piece of code is typically a class or a function
b. Isolation – separate from all other parts of the system
3. Idea is to test one unit and not multiple units
4. Usually done by the developer
5. Involves gray box testing
a. That is test the interfaces and examine results (black box)
b. Make calls to exercise the various internals (white box)

Vocabulary
1. A unit is the smallest testable part of an application.
2. In procedural programming a unit may be an individual function or procedure. Unit
tests are created by programmers or occasionally by white box testers.

Code coverage based testing (White Box Testing)


Criteria for Coverage
Function coverage - Has each function been called?

Statement coverage - Has each node in the program been executed?

Decision coverage or branch coverage - Has every edge in the program been executed? For
instance, have the requirements of each branch of each control structure (such as in IF and CASE
statements) been met as well as not met?

Condition coverage (or predicate coverage) - Has each Boolean sub-expression evaluated both
to true and false? This does not necessarily imply decision coverage.

Condition/decision coverage - Both decision and condition coverage should be satisfied.

User interface testing


The process of testing a product that uses a graphical user interface, to ensure it meets its
written specifications. This is normally done through the use of a variety of test cases.

Debugging
The methodical process of finding and reducing the number of bugs, or defects, in a computer program
or a piece of electronic hardware, thus making it behaves as expected.

Visual Studios
1. breakpoints
2. single stepping
3. runtime stack display
4. inspection of variable values
5. watches
6. step into
7. IntelliSense
Testing
1. We aren’t good enough programmers
2. We don’t concentrate enough to keep from making mistakes
3. We don’t use proper design techniques
4. We can’t distinguish what another programmer or customer says and what they really
mean
5. We feel guilty that someone else has to test our code
6. We are failures

White Box Testing

1. Given knowledge of the internal workings, you thoroughly test what is happening on the
inside
2. Close examination of procedural level of detail
3. Logical paths through code are tested
a. Conditionals
b. Loops
c. Branches (test both branches)
4. Status is examined in terms of expected values
5. Impossible to thoroughly exercise all paths
a. Exhaustive testing grows without bound
6. Can be practical if a limited number of “important” paths are evaluated
7. Can be practical to examine and test important data structures

Black Box Testing

1. Given that you know what it is supposed to do, you design tests that make it do what
you think that it should do
2. From the outside, you are testing its functionality against the specs
3. For software this is testing the interface
a. What is input to the system
b. What you can do from the outside to change the system
c. What is output from the system
4. Tests the functionality of the system by observing its external behavior
5. No knowledge of how it goes about meeting the goals

Software Architectures
Model/View/Controller architecture
The MVC pattern isolates "domain logic" (the application logic for the user) from the user interface
(input and presentation), permitting independent development, testing and maintenance of each
(separation of concerns).

Vocabulary
1. The model is used to manage information and notify observers when that information
changes. The model is the domain-specific representation of the data upon which the
application operates. Domain logic adds meaning to raw data (for example, calculating
whether today is the user's birthday, or the totals, taxes, and shipping charges for
shopping cart items). When a model changes its state, it notifies its associated views so
they can be refreshed.
o Many applications use a persistent storage mechanism such as a database to
store data. MVC does not specifically mention the data access layer because it is
understood to be underneath or encapsulated by the model. Models are not
data access objects; however, in very simple apps that have little domain logic
there is no real distinction to be made. Active Record is an accepted design
pattern which merges domain logic and data access code - a model which knows
how to persist itself.
2. The view renders the model into a form suitable for interaction, typically a user
interface element. Multiple views can exist for a single model for different purposes. A
viewport typically has a one to one correspondence with a display surface and knows
how to render to it.
3. The controller receives input and initiates a response by making calls on model objects.
A controller accepts input from the user and instructs the model and viewport to
perform actions based on that input.

Event-driven architecture
Event driven architecture is a pattern promoting the production, detection, consumption of, and
reaction to events

Vocabulary
1. An event is a significant change in state. For example, when a consumer purchases a car,
the car's state changes from "for sale" to "sold”.
Client/server architecture
The client–server model of computing is a distributed application structure that partitions tasks or
workloads between the providers of a resource or service, called servers, and service requesters, called
clients.[1]

Often clients and servers communicate over a computer network on separate hardware, but both client
and server may reside in the same system.

Vocabulary
1. A server machine is a host that is running one or more server programs which share
their resources with clients.
2. A client does not share any of its resources, but requests a server's content or service
function. Clients therefore initiate communication sessions with servers which await
incoming requests.

Examples
Email exchange, web access and database access, are built on the client–server model. Users
accessing banking services from their computer use a web browser client to send a request to a
web server at a bank

C#
Inheritance
Inheritance is one of the primary concepts of object-oriented programming. It allows you to reuse
existing code. Through effective employment of reuse, you can save time in your programming. \ Classes
can inherit other classes. (See Appendix 1.1)

Vocabulary
1. Sub-classes (or derived classes) – The new classes that inherit attributes and behavior of
the pre-existing classes.
2. Super-classes (or ancestor classes) - Parent class that sub-class inherits from.
3. Hierarchy - The inheritance relationship of sub- and super-classes

Enumerators (Enumerations, think Enum, are a way to define a choice of options)


The enum keyword is used to declare an enumeration, a distinct type consisting of a set of named
constants called the enumerator list. Every enumeration type has an underlying type, which can be any
integral type except char. The default underlying type of the enumeration elements is int. By default, the
first enumerator has the value 0, and the value of each successive enumerator is increased by 1. (See
Appendix 1.2)

IEnumerator
Delegates (Reference a method)
Allow us to hold on to a reference to an object instance and a method. They are like function pointers in
other languages, only more powerful and safer to use (type safe) ( See Appendix 1.4)

Vocabulary
Type Safe - is the extent to which a programming language discourages or prevents type
errors. A type error is erroneous or undesirable program behavior caused by a
discrepancy between differing data types.

Events
An event in C# is a way for a class to provide notifications to clients of that class when some interesting
thing happens to an object. The most familiar use for events is in graphical user interfaces; typically, the
classes that represent controls in the interface have events that are notified when the user does
something to the control (for example, click a button). Events are declared using delegates.

Programming Techniques
Building graphical user interfaces

Creating and using DLLs


DLLS (Dynamically Linked Library)
DLL is Microsoft’s implementation of shared libraries. They are a library of executable functions
or data that can be used by a windows application. They provide one or more particular
functions and a program accesses the functions by creating either a static or dynamic link to the
DLL.

Creating –

Using- Makes calls to other programs

Programming with threads


A Thread is a small set of executable instructions, which can be used to isolate a task from a process.
Multiple threads are efficient way to obtain parallelism of hardware and give interactive user interaction
to your applications.

Creating Threads
1. Create a System.Threading. Thread object.
a. Creating an object to System.Threading.Thread creates a managed thread in .Net
environment.
b. The Thread class has only one constructor, which takes a ThreadStart delegate as
parameter.
c. The ThreadStart delegate is wrap around the callback method, which will be called
when we start the thread.
2. Step 2: Create the call back function
a. This method will be a starting point for our new thread.
b. It may be an instance function of a class or a static function. Incase of instance function,
we should create an object of the class, before we create the ThreadStart delegate.
c. For static functions we can directly use the function name to instantiate the delegate.
d. The callback function should have void as both return type and parameter. Because the
ThreadStart delegate function is declared like this. (For more information on delegate
see MSDN for Delegates ).
3. Step 3: Starting the Thread.
a. We can start the newly created thread using the Threads Start method. This is an
asynchronous method, which requests the operating system to start the current thread.
4. (See Appendix 1.6)

Racing Threads – When two threads are using the same information.
Deadlock – (See Deadlock Below)

Synchronization
This refers to one of two distinct but related concepts: synchronization of processes, and
synchronization of data

Vocabulary
1. Process synchronization refers to the idea that multiple processes are to join up
or handshake at a certain point, so as to reach an agreement or commit to a
certain sequence of action.
2. Data synchronization refers to the idea of keeping multiple copies of a dataset
in coherence with one another, or to maintain data integrity. Process
synchronization primitives are commonly used to implement data
synchronization.

Transmission Synchronizations
Vocabulary
1. Synchronous transmissions are synchronized by an external clock. It uses 2 different
signals. A pulse on one signal indicates when another bit of information is ready on the
other signal.
2. Asynchronous transmissions are synchronized by special signals along the transmission
medium. It uses only 1 signal. The receiver uses transitions on that signal to figure out
the transmitter bit rate ("autobaud") and timing, and set a local clock to the proper
timing, typically using a phase-locked loop (PLL) to synchronize with the transmission
rate. A pulse from the local clock indicates when another bit is ready.

Advantages
Disadvantages

 Simple, doesn't require


synchronization of both
communication sides
 Cheap, timing is not as
 Large relative overhead, a
critical as for synchronous high proportion of the
Asynchronous transmission, therefore transmitted bits are uniquely
transmission hardware can be made for control purposes and
cheaper thus carry no useful
 Set-up is very fast, so well information
suited for applications
where messages are
generated at irregular
intervals, for example
data entry from the
keyboard

 Lower overhead and thus,


greater throughput  Slightly more complex
Synchronous  Hardware is more
transmission expensive...

Locks
Lock is a synchronization mechanism for enforcing limits on access to a resource in an environment
where there are many threads of execution. Locks are one way of enforcing concurrency control
policies.
Problems with locks:

 They will cause blocking, which means some threads/processes have to wait until a lock
(or a whole set of locks) is released.
 Locks can be vulnerable to failures and faults that are often very subtle and may be
difficult to reproduce reliably. One example is the deadlock
 Lock contention limits scalability and adds complexity.
 Priority inversion. High priority threads/processes cannot proceed if a low priority
thread/process is holding the common lock.
 Convoying. All other threads have to wait if a thread holding a lock is descheduled due
to a time-slice interrupt or page fault
 Hard to debug: Bugs associated with locks are time dependent. They are extremely hard
to replicate.
 There must be sufficient resources

Deadlock
This is a situation wherein two or more competing actions are each waiting for the other to finish, and
thus neither ever does. It is often seen in a paradox like the "chicken or the egg". The concept of a Catch
22 is similar. (See Appendix 1.3 for example)

Sockets
They are used to create connections between two objects. There are Asynchronous and Synchronous
(see Transmission Synch) types of connections. Each begins with a handshake and keeps connected until
one side disconnects

A socket is like a handle to a file, which is used to open the path to communicate with another
machine. It resembles the file IO, as does the serial communication.

Using socket programming, we can have communication between two applications. The
applications are typically on different computers or in the same computer.

For the two applications to talk to each either on the same or different computers, one
application is generally a server that keeps listening to the incoming requests and the other
application acts as a client and makes the connection to the server application.
Appendix

Listing 8-1 shows two classes. The top class is


1.1 named ParentClass and the main class is called
ChildClass. What we want to do is create a child
Listing 8-1. Inheritance: BaseClass.cs class, using existing code from ParentClass.
First we must declare our intention to use
using System; ParentClass as the base class of ChildClass. This
is accomplished through the ChildClass
public class ParentClass declaration public class ChildClass : ParentClass.
{ The base class is specified by adding a colon, ":",
    public ParentClass() after the derived class identifier and then
    { specifying the base class name.
        Console.WriteLine("Parent Constructor."); Note: C# supports single class inheritance only.
    } Therefore, you can specify only one base class
to inherit from. However, it does allow multiple
    public void print() interface inheritance, a subject covered in a
    { later lesson.
        Console.WriteLine("I'm a Parent Class."); ChildClass has exactly the same capabilities as
    } ParentClass. Because of this, you can also say
} ChildClass "is" a ParentClass. This is shown in
the Main() method of ChildClass when the
public class ChildClass : ParentClass print() method is called. ChildClass does not
{ have its own print() method, so it uses the
    public ChildClass() ParentClass print() method. You can see the
    { results in the 3rd line of output.
        Console.WriteLine("Child Constructor."); Base classes are automatically instantiated
    } before derived classes. Notice the output from
Listing 8-1. The ParentClass constructor
    public static void Main() executed before the ChildClass constructor.
    {
        ChildClass child = new ChildClass();
1.2
        child.print();
    } Dim QUEEN as Integer = 12
} Dim KING as Integer = 13
Output: Dim ACE as Integer = 14

Parent Constructor. Dim card as Integer = 13


Child Constructor.
I'm a Parent Class.
Then you could use an IF statement like this
See how it's much more readable and much
If card = KING then .... and so on.... more safe is it, card now cannot equal 15

That was pretty normal code for a while but you


can see it's a bit of hassle and it's not very safe,
imagine if the card was set to 15! thats not a 1.3
valid card but it's a valid value for an integer.
Also setting card to 13 doesn't mean very much,
it's not readable so it's easier to make a Suppose there are two locks, A and B. Thread 1 holds
lock A and is waiting on lock B, and thread 2
mistake. holdslock B and is waiting on lock A. That’s a
deadlock.

Ok now comes Enumerations.....


1.4
   Public Enum FaceValue Class Delegate {
        Two = 2 Public static bool MethodToCall(string s)
        Three = 3 {
        Four = 4 //do something
        Five = 5 }
        Six = 6
Public delegate void Delegate1(string s);
        Seven = 7
Public delegate void Delegate2(string s);
        Eight = 8
        Nine = 9 static void Main (string[]args)
        Ten = 10 {
        Jack = 11 Delegate2 del;
        Queen = 12 Del = new Delegate2(Method to Call);
Del(“Hello”);
        King = 13
}
        Ace = 14
    End Enum

What this does is it creates a data type called 1.5


FaceValue that can only be set to a value Declare an Event:
between 2 and 14. It's an actual data type that
replaces the integer that was used in the first To declare an event inside a class, first a
example. delegate type for the event must be declared,
if none is already declared.
Dim card as FaceValue
public delegate void
card = FaceValue.King ChangedEventHandler(object sender,
EventArgs e);
If card = FaceValue.King ... and so on The delegate type defines the set of
arguments that are passed to the method that
handles the event. Multiple events can share
the same delegate type, so this step is only
necessary if no suitable delegate type has
already been declared.
Next, the event itself is declared.
public event ChangedEventHandler
Changed

1.6
using System.Threading;

Thread thread = new Thread(new


ThreadStart(WorkThreadFunction));
thread.Start();

public void WorkThreadFunction()


{
try
{
// do any background work
}
catch (Exception ex)
{
// log errors
}
}

You might also like