Vous êtes sur la page 1sur 14

Software Development

Fundamentals
General Software Development
Application Life-Cycle Management

This is the typical Life-Cycle management for an application. Is a key


process to help us. The first step is Requirements. Before we decide to
create a software, we need to envision a product, a software. Once we come
up with the idea, we need to find the requirements: features, what to do,
the result we want, etc. Normally this requirements are documented to
explain what are the specifications and goal of our application.
After this, we need to create the Design. Different ways to program,
different architecture to achieve what we want to do. We are creating a
design how the application work and how we are going to create it.
Storyboards can be used to see how the application flows on the user
interface.
Next we go to Development, the people who write the code. They create a
Technical Specification, a document that dictates how we are going to
actually create the functionality in code. What technologies to use, what
data structures to implement, how to access data, etc.
Then we have Test. We have testing during the development process, to
test part of code (small parts). Then we have the test team. They look at the
functional specification, know and understand what the program is
supposed to do and then write automated test routines to check the
functionalities. There is also user acceptance test were users test our final
code.

The next phase is Maintain. After we release our application, we need to


maintain. We can record pieces of information about how it operates, for
performance checking, search for bugs, etc. Is important to maintain our
code. Fix bugs, launch new versions, check for security, etc.

Application Specification
Sometimes it can be called functional specifications, but is the part of the
life-cycle process. The more important parts for a software developer are
Feature List and Feature Overview. The Feature List gives the description
of what we want to have as a result, and what to do to end there. For
example, checking a price:

It only explains what we want to do, not how to do it. We go deeper on


feature overview. Feature Overview shows us what problems we want to
solve and how to get there. This documents are normally created on the 2
first steps of the life-cycle of our application. On the Design phase we
decide what the user will see and not see.

Core Programing
Computer Storage
This explains how a computer stores information and it processes
information. Computers use binary concept, 0 and 1, on or off. Physically we
are dealing with the presence of voltage or no voltage. We need to have
representations for Character Sets, symbols that make up the words and
letters we use. We represent them with series of 0 and 1, bits and bytes. A
0 or a 1 is a bit. When we start to aggregate them we start to have bytes,
megabytes, gigabytes, etc.

When a computer runs a program, cant run it directly from a


storage device. It has to access that information directly in
computer memory (RAM). We only can use a certain amount of memory,
not an unlimited amount. That gives us some restrictions.
We also have ASCI charts, which is a way to represent special symbols,
punctuation marks, letters and numbers on our binary system. Our
programming languages today are on a hinger level, so we dont program in
1 and 0s. Programming language allows to write code using a similar
syntax to English, and the compiler in the background that takes those
instructions and exports into a binary version that the computer can
understand. Also depending on the CPU we are using, we need specific
instruction sets.

Variables, Constants and Data Types

Variable provides a temporary, named storage location in computer


memory. Computers deal with memory addresses. With variables,
name storage locations, we save this information to that memory
address, but the computer does all the mapping. Just need to
remember the name of the variable. Can change values of a
variable.

Constant either a named storage location or literal value. Cannot


be changed during program execution. We can still assign a
value to a constant but we need to do it when we create the
constant. Can read the value, but not change during execution.
Literal constants are something like number 1, letter C, etc. We cant
change those values. 1 will always be 1, etc. We can store a constant
in a variable. For example number = 1, where number is the variable
and 1 the constant.

Data Types numeric, character, special

We use specific data types because the computer needs to know that
because of the operations we might want to perform with our data. For

example using + with text and number. Mathematically we can0t do it, so


the computer doesnt know what to do.
Also when the compiler sees the data type it knows how much memory to
set aside for that variable.

Data Structures
We need to store multiple pieces of potentially related information. Some of
the data structures available are:

Arrays
Stacks
Queues
Dictionaries

Arrays
An array is a collection of similar data types accessed by index. For
example we have this array example:

We cant forget that they store the same data type. Normally we have
strings, numeric values, or in OOB, a collection of objects. We can define an
array as a random access data structure, so we can access the values in
this array at any time, in value, in any order, using the index value. The
index start at 0. The index does not relay to the value on that index.
Data structures will be represented by a variable, so we need to name
this data structure. We have a single name that represents multiple items.
To create an array of strings, we will use the following code:

We create a new array called myArray, with data type string before the
name. The order of the array is determined by the order we put the values
into the array.

Stack
Stack is a collection of objects, accessed by pop and push. We use
stacks on some specific programing scenarios. On a stack of trays, we cant
access the last tray without damaging the structure. To get to a specific
tray, we need to remove all the others on to top of that one.
So when we look at a stack, we can consider when we put values on the
stack, we push the values to the stack. When we take a value off the
stack, we pop the value from the stack. We put the values on the top of
the stack, so it keeps pushing the first values down. Is a FILO (First In Last
Out) data structure. This is an example of a stack, called myStack.

We use the .Push method to stack objects into our stack. At the end we
iterate into the stack and use .Pop to pop a value out of the stack. Also we
need to explicit convert the item to string (.ToString) in order to print it
correctly. Remember that the last item is the first one getting out of the
stack (FILO).
When we pop the value from the stack we are literally taking it off.
The stack sizes decreases while we pop values out.

Queue
A queue is a collection of objects, accessed by queuing and
dequeuing. Similar to a line at the motor vehicle license branch.

This is considered a FIFO (First In First Out data structure). The first
piece of data going into the queue is the first piece of data out of the queue.
You access that information through different methods that pull the items off
to the queue. This is an example of a queue:

We add values to the queue using .Enqueue, giving it the order as we


add items to the queue. In C# we can use .Peek to see the first item on the
queue.
To retrieve items from the queue we use .Dequeue and we dont give it a
value. A queue always give us the first item (FIFO). When we dequeue an
item from the queue we decrease the number of items in the
queue.

Dictionary
A dictionary is a collection of objects that are accessed by using a
key. For examples:

Its similar to an array, but instead of accessing this values through an index
like we did with the array, we access them through the use of a key. Its
easier to use the key instead of and index, because we give this key a name
we need. For example using it with names, etc. This a dictionary sample:

We create a variable Dictionary, with strings. We add values to the


dictionary using the key. We access the item by using the key instead
of the order we put the values in or by the index.

Algorithms
We can think of an algorithm as a mathematically formula or a recipe, etc.
We should think that an algorithm is a solution to a problem. We
have a problem and we will take steps to solve that problem, like we use a
recipe, adding ingredients, mixing, cook, and check if its OK. If not, make
some decision until is good to eat. We have a flow in a recipe, as we have in
an algorithm. We need to look at a problem logically.
We can have for example a bubble sort, and that is an algorithm that we use
to compare 2 values, compare them, and then swap if the first is greater
than the second until we reach the end of the list, looping until we get to the
end of the list. Is the most inefficient way to sort values.

Decision Structures
We use the diamond boxes to illustrate a decision. We ask questions as we
code, and the program will answer that questions. For taking decisions we
can use:

If, If-else, If-else-if


Switch or Select Case

This allows to evaluate a condition, take a look at whether its true or false,
and take an action based on that. This is essentially what decision making
do. Allows to change the flow of the code.

The condition happens inside the {}. The code inside the if will execute if
the condition is true. We use = to assign a value. We use == as a
comparison operator.

We use if-else to take action if the comparison is true, and then take some
action is false. If its not true it will execute the else part of the code.
In this case the code will run always something, if its true or false.

In this case we have 2 conditions, and if its not true, we will execute the
last part, the last one else. To avoid problems with a long nesting of if else
code, we can use switch.
Switch gives a cleaner way of checking multiple conditions and
execute code based on that. This is our example of a switch.

We check our condition first, on the switch(*condition*), and we compare it


to the case statements used bellow. In this case we will evaluate
switchCondition = 3 against case 1, 2, 3 and have a default value (default is
optional). Default value will be used when no condition is met on the cases.
We must use break at each case to get out of the switch statement.

Repetition
In this section we will analyze parts of programs that repeats or loops, and
repetition is something we will use in programming a lot. Bubble sort is
something that repeats for example. We will cover:

For loops
While loops
Do-while loops
Recursion

For loops

For loop is a structure that do something repeating until a condition is false.


With will loop while condition is true. We will use a sentinel value that will
allows us to terminate the loop. We have to do something to the sentinel
value so it doesnt run infinitely.
We declare an initialization value, and int and give value of 0. Then we will
have the condition that we check to see if we loop again or exit the loop. At
the end we increment our condition value (sentinel value), saying that it ran
1 time, in this example.

While loops

While the condition is true, it will run our loop, until our condition is false.
But, in this case we need to increment the value on our loop, so it
doesnt loop forever.

Do-While loops

On a do-while loop we have the do portion of code, that iterates and also
increments our condition value. At the end of the code we will declare

the while, the condition for our code to loop. We only do the condition
check at the end of the loop so the code will always run before
checking the condition. Even if the condition is not met in the beginning,
it will run the code once.

Recursion

We declare a long variable, and then we do a function call. We will call


the Factorial function declared bellow on our code example. We pass a value
of 10 to our function. Then we will do our factorial function. If our value
equals 0, we will return one, we will exit our code.
We call recursion because we will call the same code again in the
return n * Factorial (n 1). At the end we will take the values of the stack
and will start multiplying them and return our value.

Object-Oriented Programming
Object-oriented programming is the most used by programmers nowadays,
helping modeling real world objects into programming concepts. Before we
used sequential programming than run top from bottom. OOP helps us in
that.

Fundamentals of Classes
We can considerer a class like a blueprint. As a common blueprint, it
has very specific information about what we are going to build (number of
windows, size, etc.). Also gives us the behaviors of what we are going to
build. In the case of a car, it can accelerate, break, turn, etc. So a class
includes data (attributes) and behavior. We create a mapping how this
class will be in our code. Objects are created in code to represent the
class.

The difference between the two is that the class is the blueprint, so we cant
live in the class, but the object is the instance of that blueprint and we can
live in that object (example of the house).
When we create a class file it includes all of the data, or what we
refer to as the attributes (size, shape) and it includes all of the
behaviors (what object is capable) of that specific class or object.
We have the example of a class named Animal. The attributes are: type,
weight and color this are considered the data or the attribute of
that particular animal class. Make noise and move are examples of the
behaviors of the animal class.
When we create the class, the attributes or the data that well store in the
class will be represented through variables and constants and can create
data structures within it to represent collections of pieces of data that will
actually be represented as well.
In sum, classes are data and behavior all in one.

Introducing Encapsulation
Creating data and behavior in a class is known as encapsulation. But it
goes beyond, because we can actually hide data from the user. The user in
this case is the programmer using that class in code.
With that we create a black box. This term means that the user can take
our black box, our code and use it without knowing how it does what it
does. The behaviors is exposed through interfaces. They cant
manipulate what it do. They use it through the interface.
We can also control what they do with the data. They cant change
values directly in the class. They must use our programming interface to set
the values and retrieve the values. This gives us better control over the data
users pass in and get back in on their system.
This is the examples of a class, called Animal:

We name the class as Animal

We have the member variables, our attributes (type, weight and


color). We have the data types to encapsulate our data. By declaring
private, we cant set this variables values or type directly.
To change the values we use Properties, our interface, to get and
set this specific private member variables. The property that access
our variable, or attribute, starts with an uppercase.

Get is used to return the value, so we use the return statement.


Set gets the value from something value, something in C# uses in its
property methods that says this is the value that somebody has passed into
set what the type is. We pass to type the value that the user set.
Property is simply a way to gain access to the variable to set or
retrieve its value. The data itself is stored in the local variable. We can
make a value read only by not including the set. Lets see a behavior, or
instance methods:

Public keyword means that users are allowed to gain access to


these because they are public.

Inheritance
With inheritance, data and behavior are taken from another class. This
creates the concept of super classes, sub classes or base classes and a
derived class, etc. This means that the base class becomes the parent
and the derived class or sub class becomes the class that does the
inheriting. It collects the values from the parent/super class.
Inheritance allows to create a class with a base that can be used across
different subclasses. It provides base functionality for similar objects.
Allows code reuse. Think of character traits inherited from a parent.
With the animal class examples, we create that base class with the
attributes, and then create animals like dogs, cats, etc., that have the same
base (size, color, etc.). This characteristics and inherited from the parent,
the super class. Super class has the aspects, functionality and
attributes that we can reuse in sub classes. With that we dont need to
write the all code again. Lets see an example:
Using the Animal class, we create a class Dog, with Animal as base:

Even with no data, the Dog class inherited from the Animal class. This is
demonstrated by the : Animal. We create a new dog, and well say that
equals a new dog.

This is the syntax for instantiating an object of the dog class. In OOP is
referred as instantiation. Dog is the blueprint. Spot is the instance of a dog
that we decided to create in our code. Because we use super/base class
Dog, when we want to access to attributes of Spot, we will have the
attributes of the class Dog.

We see here color, type and weight. Intelisense will give as all the
functionality available to Spot. What we see is inheritance in action.

Polymorphism
Its another key of object-oriented programming. It means that we can
have multiple versions, different versions, of the same thing.
Polymorphism means that a behavior change, or an attribute change.
Wesaw the inheritance and Spot having functionality of Animal class. But
we can also make changes to our dog class that suits what we want
to do. For example:

The class Dog inherited from Animal class. The animal class doesnt have a
Breed functionality. But we can code that in the Dog class and now Dog
class as Breed property while Animal dont. The class that inherits can
me modified and have other properties that the base class doesnt have. In
the case of Animal, a specific type of animal can have different
characteristics depending on the species. We don change our super
class.

Polymorphism also allows us to change functionality. Heres an example:

We add wagtail functionality that Dog class now has, but Animal class
doesnt. But we can also override a virtual method, in this case
MakeNoise(). We can change the behavior of that virtual method. Animal
has MakeNoise() as base, and we add Bark to the dog class by overriding
our method. We change the functionality has we need on the subclass.