Sie sind auf Seite 1von 15

Eduardo Calvachi

Consulta # 2 Lenguaje de Prog 1

Classes
In object-oriented programming, a class is a construct that is used as a blueprint
(or template) to create objects of that class. This blueprint describes the state
and behavior that the objects of the class all share. An object of a given class is
called an instance of the class. The class that contains (and was used to create)
that instance can be considered as the type of that object, e.g. an object instance
of the "Fruit" class would be of the type "Fruit".

A class usually represents a noun, such as a person, place or (possibly


quite abstract) thing - it is a model of a concept within a computer program.
Fundamentally, it encapsulates the state and behavior of the concept it
represents. It encapsulates state through data placeholders called attributes
(or member variables orinstance variables); it encapsulates behavior through
reusable sections of code called methods.

Source: http://en.wikipedia.org/wiki/Class_(computer_programming)
Variables in C#
Variables represent storage locations. Every variable has a type that determines the values
to be stored in the variable. C# is a type-safe language and the C# compiler guarantees that
values stored in variables are always of the appropriate type. The value of a variable can be
changed through assignment or through use of the ++ and - operators in the case of numeric
variables.

Variables are values that can change as much as needed during the execution of a program.
One reason you need variables in a program is to hold the results of a calculation. Hence,
variables are locations in memory in which values can be stored.

Variable Declarations

In C# all variables must be declared before they are used. In the declaration you must specify
a data type and a name for the variable so that memory can be set aside for the variable. An
optional initial value can be included with the declaration if you know what the value should be
to start.

Syntax for variable declaration

[scope] [data type] [=initial value];

Description

The scope determines the accessibility of the variable (public, local, private) and the default is
private. The data type specifies what kind of data the variable will hold. Optionally the variable
can be initialised to a specific value. All variables must be initialised (given a value) before they
are used in any calculation. If the variables are not initialised, the compilation of the program will
fail.

Value Type Variables


Value type variables are also known as stack variables because they are stored on the stack.
Value type variables can be directly declared and referenced. As the variables go out of
scope, they are removed from the stack, ensuring the proper destruction of the variables. As
the variables are created on the stack, they are not initialised; that is the responsibility of the
program. The use of an uncapitalized variable will result in a compiler error.

Example Value variable

int n; //uncapitalized int

Long l = 327 //initialised long

Float f = 3.13 F; //float initialised from single-precision literal

Reference Type Variables

Reference type variables are made up of two parts: the reference on the stack and the object on
the heap. The creation of the object and the reference to the object is commonly known as the
instantiation of the object.

Example Reference variable

To declare a reference-type variable, the syntax used is:

string strMimico;city objToronto = null;object objGeneric;

Example Object variable:

To create an object on the heap, we declare the variable reference and the we Instantiate the
object on the heap by calling the new operator.

Source: http://tools.devshed.com/c/a/Web-Development/C-Variables/
Pascal Case
Words created by concatenating capitalized words. An example is this page's title, PascalCase.
Sometimes called "UpperCamelCase". Distinguished from CamelCase by the restriction that
the first letter must be upper case. ("camelCase" isn't PascalCase, but "PascalCase" is.)
WikiCase is more restrictive than PascalCase: WikiCase does not allow 1-letter words, but
PascalCase does. ("ReadARecord" is PascalCase but not WikiCase.) In 30 years I never heard
it called "PascalCase" before, and I can't see that it truly had anything to do with Pascal. Is
this merely what it's called in the Microsoft world? See InAllMyYearsIveNever Considering
Microsoft's C# standard is PascalCase, that's what most of the Microsoft guys will call it.
Besides, "upper CamelCase" is dumb. We already have PascalCase and CamelCase, one for
classes and methods, and one for variables.

Source: http://c2.com/cgi/wiki?PascalCase
Camel Case
New words created by smashing together capitalized words.
● Are they really smashed? Such violence. Aren't they more cuddly, and in love?
There is disagreement about the precise meaning of the term CamelCase. Some hold that
camel case words must begin with a lowercase letter (thisIsAnExample), others not:

lower camel case: thisIsAnExample. SomePeopleConsiderThisAnExample.

upper camel case, a.k.a. PascalCase: thisIsAnExample. ThisIsNotAnExample.

ThisIsAnExample. thisIsNotAnExample. (Some people consider this term an OxyMoron.)

In some contexts, CamelCase words may include digits. See CapitalizationRules for synonyms
and related terms. History According to this document - http://www.fpml.com/documents/
standard/FpML-10b2/faq.html#WDConventions2 on the Financial Products Markup Language
site, camelCase is a naming convention that originated with SmalltalkLanguage. Anybody want
to confirm or deny that? Perhaps give some history? -- StevenNewton
● This page CamelCase provides a bit of history and supports the SmalltalkLanguage
connection. -- HansWobbe
I think I remember this style of word break in BCPL code (e.g., at BBN), long before Smalltalk,
in the early 70s. -- ChrisRyland? The earliest commercial example of (upper) CamelCase is the
1950s "CinemaScope" film projection system.

Source: http://c2.com/cgi/wiki?CamelCase
Encapsulation
Encapsulation is the ability of an object to be a container (or capsule) for related properties
(ie. data variables) and methods (ie. functions). Older languages did not enforce any property/
method relationships. This often resulted in side effects where variables had their contents
changed or reused in unexpected ways and spaghetti code that was difficult to unravel,
understand and maintain. Encapsulation is one of three fundamental principles in object
oriented programming.
Data hiding is the ability of objects to shield variables from external access. It is a useful
consequence of the encapsulation principle. Those variables marked as private can only be
seen or modified through the use of public accessor and mutator methods. This permits validity
checking at run time. Access to other variables can be allowed but with tight control on how it is
done. Methods can also be completely hidden from external use. Those that are made visible
externally can only be called by using the object's front door (ie. there is no 'goto' branching
concept).
A class is a template or prototype for each of many object instances made to the class design.
The class specifies the properties (data) and methods (actions) that objects can work with.

Alternative Deff:

"Encapsulation is the concept that an object should totally separate its interface from its
implementation. All the data and implementation code for an object should be entirely hidden
behind its interface.
The idea is that we can create an interface (Public methods in a class) and, as long as that
interface remains consistent, the application can interact with our objects. This remains true
even if we entirely rewrite the code within a given method thus the interface is independent of
the implementation."

Sources:
http://home.cogeco.ca/~ve3ll/jatutor4.htm
http://www.developer.com/java/ent/article.php/935351/The-Essence-of-OOP-Using-Java-
Objects-and-Encapsulation.htm
Debugging

In computers, debugging is the process of locating and fixing or bypassing bugs (errors) in
computer program code or the engineering of a hardware device. To debug a program or
hardware device is to start with a problem, isolate the source of the problem, and then fix
it. A user of a program that does not know how to fix the problem may learn enough about
the problem to be able to avoid it until it is permanently fixed. When someone says they've
debugged a program or "worked the bugs out" of a program, they imply that they fixed it so that
the bugs no longer exist.
Debugging is a necessary process in almost any new software or hardware development
process, whether a commercial product or an enterprise or personal application program. For
complex products, debugging is done as the result of the unit test for the smallest unit of a
system, again at component test when parts are brought together, again at system test when
the product is used with other existing products, and again during customer beta test, when
users try the product out in a real world situation.
Because most computer programs and many programmed hardware devices contain
thousands of lines of code, almost any new product is likely to contain a few bugs. Invariably,
the bugs in the functions that get most use are found and fixed first. An early version of a
program that has lots of bugs is referred to as "buggy."
Debugging tools (called debuggers) help identify coding errors at various development stages.
Some programming language packages include a facility for checking the code for errors as it is
being written.

Source:http://searchsoftwarequality.techtarget.com/definition/debugging
Parameters and Arguments
In computer programming, a parameter is a special kind of variable, used in a subroutine to
refer to one of the pieces of data provided as input to the subroutine. These pieces of data
are called arguments. An ordered list of parameters is usually included in the definition of
a subroutine, so that, each time the subroutine is called, its arguments for that call can be
assigned to the corresponding parameters.

Parameters and arguments


These two terms are sometimes loosely used interchangeably; in particular, "argument"
is sometimes used in place of "parameter". Nevertheless, there is a difference. Properly,
parameters appear in procedure definitions; arguments appear in procedure calls.

A parameter is an intrinsic property of the procedure, included in its definition. For example, in
many languages, a minimal procedure to add two supplied integers together and calculate the
sum total would need two parameters, one for each expected integer. In general, a procedure
may be defined with any number of parameters, or no parameters at all. If a procedure has
parameters, the part of its definition that specifies the parameters is called its parameter list.

By contrast, the arguments are the values actually supplied to the procedure when it is called.
Unlike the parameters, which form an unchanging part of the procedure's definition, the
arguments can, and often do, vary from call to call. Each time a procedure is called, the part of
the procedure call that specifies the arguments is called the argument list.

Although parameters are also commonly referred to as arguments, arguments are more
properly thought of as the actual values or references assigned to the parameter variables
when the subroutine is called at runtime. When discussing code that is calling into a subroutine,
any values or references passed into the subroutine are the arguments, and the place in the
code where these values or references are given is the parameter list. When discussing the
code inside the subroutine definition, the variables in the subroutine's parameter list are the
parameters, while the values of the parameters at runtime are the arguments.

Many programmers use parameter and argument interchangeably, depending on context


to distinguish the meaning. The term formal parameter refers to the variable as found in the
function definition (parameter), while actual parameter refers to the actual value passed
(argument).

Sources: http://en.wikipedia.org/wiki/Parameter_%28computer_programming%29

Override vs Overload
Polymorphism is the ability of a class instance to behave as if it were an instance of another
class in its inheritance tree, most often one of its ancestor classes. For example, in Java all
classes inherit from Object. Therefore, you can create a variable of type Object and assign to it
an instance of any class.

An override is a type of function which occurs in a class which inherits from another class.
An override function "replaces" a function inherited from the base class, but does so in such
a way that it is called even when an instance of its class is pretending to be a different type
through polymorphism. Referring to the previous example, you could define your own class and
override the ToString() function. Because this function is inherited from Object, it will still be
available if you copy an instance of this class into an Object-type variable. Normally, if you call
ToString() on your class while it is pretending to be an Object, the version of ToString which will
actually fire is the one defined on Object itself. However, because the function is an override,
the definition of ToString() from your class is used even when the class instance's true type is
hidden behind polymorphism.

Overloading is the action of defining multiple methods with the same name, but with different
parameters. It is unrelated to either overriding or polymorphism.

Source: http://stackoverflow.com/questions/154577/polymorphism-vs-overriding-vs-overloading
Solution vs Project
A Solution is a container for one or more projects, similar to a Project Group
in VB 6. A Visual Studio .NET Solution
can contain projects of different types, using different .NET languages.

Source: http://bytes.com/topic/visual-basic-net/answers/365906-solution-vs-project
Instantiated vs Initialized
A variable is initialized with a value. An object is instantiated when memory
is allocated for it and it's constructor has been run.
For instance here is a variable:
Dim obj as Object
This variable has not been initialized. Once I assign a value to the obj
variable, the variable will be initialized. Here are examples of initialization:
obj = 1
obj = "foo"
Instantiation is a very different thing but is related since instantiation is
usually followed by initialization:
Dim obj As New Object()
In the preceding line of code, the obj variable is initialized with the
reference to the new Object that was instantiated. We say that the new
Object was instantiated because we have created a new instance of it.
Now I believe that VB.NET makes this a lot more confusing than C#
because it is not clear that an assignment is taking place in the code
above. In C# it is much clearer that there is both an instantiation of an
instance and an initialization of a variable:
Object obj = new Object();

Source:http://stackoverflow.com/questions/2330767/what-is-the-difference-between-
instantiated-and-initialized
C# Data Types
C# is a strongly typed language; therefore every variable and object
must have a declared type.

A data type can be described as being either:


● A built-in data type, such as an int or char, or
● A user-defined data type, such as a class or interface.
● Data types can also be defined as being either:
● Value Types (C# Reference), which store values, or
● Reference Types (C# Reference), which store references to
the actual data.

Value Types (C# Reference)


The value types consist of two main categories:
● Structs
● Enumerations
Structs fall into these categories:
● Numeric types
Integral types
Floating-point types
decimal
● bool
● User defined structs.

Reference Types (C# Reference)


Variables of reference types, referred to as objects, store references to
the actual data. This section introduces the following keywords used to
declare reference types:
● class
● interface
● delegate
This section also introduces the following built-in reference types:
● object
● string

Arrays
An array is a container object that holds a fixed number of values of a single type. The
length of an array is established when the array is created. After creation, its length is
fixed. You've seen an example of arrays already, in the main method of the "Hello World!"
application. This section discusses arrays in greater detail.

An array of ten elements


Each item in an array is called an element, and each element is accessed by its numerical
index. As shown in the above illustration, numbering begins with 0. The 9th element, for
example, would therefore be accessed at index 8.

Source: http://download.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
Assembly Language

An assembly language is a low-level programming language for computers,


microprocessors, microcontrollers, and other programmable devices. It
implements a symbolic representation of the machine codes and other constants
needed to program a given CPU architecture. This representation is usually
defined by the hardware manufacturer, and is based on mnemonics that
symbolize processing steps (instructions),processor registers, memory locations,
and other language features. An assembly language is thus specific to a certain
physical (or virtual) computer architecture. This is in contrast to most high-level
programming languages, which, ideally, are portable.
A utility program called an assembler is used to translate assembly language
statements into the target computer's machine code. The assembler performs
a more or less isomorphic translation (a one-to-one mapping) from mnemonic
statements into machine instructions and data. This is in contrast with high-
level languages, in which a single statement generally results in many machine
instructions.
Many sophisticated assemblers offer additional mechanisms to facilitate program
development, control the assembly process, and aid debugging. In particular,
most modern assemblers include a macro facility (described below), and are
called macro assemblers.
Source: http://en.wikipedia.org/wiki/Assembly_language
Control Flow

In computer science, control flow (or alternatively, flow of control) refers to


the order in which the individual statements, instructions, or function calls of an
imperative or a declarative program are executed or evaluated.
Within an imperative programming language, a control flow statement is a
statement whose execution results in a choice being made as to which of two
or more paths should be followed. For non-strict functional languages, functions
and language constructs exist to achieve the same result, but they are not
necessarily called control flow statements.
The kinds of control flow statements supported by different languages vary, but
can be categorized by their effect:
● continuation at a different statement (unconditional branch or jump),
● executing a set of statements only if some condition is met (choice - i.e.
conditional branch),
● executing a set of statements zero or more times, until some condition is
met (i.e. loop - the same as conditional branch),
● executing a set of distant statements, after which the flow of control
usually returns (subroutines, coroutines, and continuations),
● stopping the program, preventing any further execution (unconditional
halt).

Source: http://en.wikipedia.org/wiki/Control_flow

Das könnte Ihnen auch gefallen