380 Study
380 Study
380 Study
Modularization: Breaking down a program into smaller units of code such as methods
Top-Down Design: Breaking down an algorithm into methods. Breaks overall task of program
into subtasks
1) Access Modifier:
Private called only by code inside same class as method
Public can be called by code outside of the class
Ex of Method:
Private void DisplayMessage()
{
Messagebox.show(“This is the display message Method”);
}
Call statements: Methods are executed by call statements – format is the name of the method
followed by parentheses
Return point: Memory address of location to which method should return, the system needs
to know where program should return after method ends
Argument: Any piece of data that is passed into a method
Parameter: A variable that receives an argument that is passed into a method, usually
consisting of a data type, and variable name
Or
Int myVar = 99;
SetToZero(ref myVar);
Note: Output parameters do not have have a value attached to it like Reference variables do
1) Output Parameter: Declare by using the ‘out’ keyword before the parameter variables
data type
Ex: Private void SetToZero( out int number)
{
number = 0
}
2) Reference Parameter: Declare by using the ‘ref’ keyword before parameter variables
data type
Ex: Private void SetToZero( ref int number)
{
number = 0
}
Arrays/Lists –
Two categories that data types fall into for C#/.NET framework
1) Value types: Variable used to hold a value, such as 23. Actually holds data
2) Reference types: Variable used to reference an object, used to reference objects and
does not hold data. Links the variable that holds data to the object
Array: Allows you to store a group of items of the same data type together in memory.
Variables are not ideal for storing/processing lists of data so use arrays. Arrays are reference
type objects.
Format of an Array:
1) DataType[ ]arrayName;
arrayName = new DataType[Array size];
Elements: Storage locations in arrays, each element in an array is assigned a unique number
known as a subscript
Subscript: Starts with 0, used to identify specific elements in an array
Ex:
Const int SIZE = 6
Int [] numbersArray = new int [SIZE]
numbersArray[0] = 20
numbersArray[1] = 31
numbersArray[2] = 24
numbersArray[3] = 26
Files/Arrays:
2-Dimensional Arrays:
Stores multiple sets of data
Illustrated with rows and columns
Lists:
Class in .NET framework that is similar to an array with the following advantages:
1) List object does not require size declaration
2) You can add or remove items from a list
Format of a list:
List <DataType> ListName = new List <DataType> ();
Ex:
List<String>namesList = new List <String>();
List<Int>numbersList = new List <Int>();
Encapsulation: Fundamental concept of OOP. Let’s you control data and operations within a
class that are exposed to other classes
Property: Class member that holds a piece of data about an object, can be implemented as
special methods that set and get the value of corresponding fields
Get accessor: if not empty, is a method that returns the property’s value because it has a return
statement. Executed when the property is read.
Set accessor: if not empty, gets the value stored in the backing field and assigns the value to the
property
Overloaded methods: A class can have multiple versions of the same method. This is a method
with the same name but different parameters.
Signature of a method: Consists of method name, datatype, argument kind
ShowDialogue: Displays a form on the screen and it gives that form the focus
ModalForm: or Dialogue box, must be closed or hidden before you can continue working with
the rest of the application. When declard, no other form in the application can receive the
focus until modal form is closed.
ModelessForm: Allows user to switch focus to another form while it is displayed
*Product Class
Public class product
{
Private String Code
Private String Description
Private Decimal Price
Is-a relationship: When one object is a specialized version of another object, relationship exists
Ex:
grasshopper is an insect
bumblebee is an insect
specialization is a generalization
Logic behind relationship: All insects have certain common characteristics and can be described
by an insect class. Grasshoppers and bumblebees have unique characteristics and can be
described by a grasshopper class and a bumblebee class
Is-a relationship implies specialized object has all characteristics of the generalized object
Specialized object has additional characteristics that make it special, general objects do
not have them
Is-a relationship allows you to extend capabilities of a class by creating another class that is a
specialized version of it
Polymorphism: objects ability to take many forms. Allows derived classes to have methods with
same names as methods in their base classes. Gives ability for a program to call the correct
method. When a derived class inherits from a base class, it gains all the methods, fields,
properties, and events of the base class.
In order for an instance of a derived class to completely take over a class member from a
base class, the base class has to declare that member as virtual
Fields cannot be virtual
Only methods, properties, and events can be virtual
A derived class has the option of using the override keyword to replace the base class
implementation with its own
Abstract Class: Serves as a base class but is not instantiated itself. Only provides some class
members to its derived classes