General Coding Flashcards
The STACK is…..
The stack is the block of memory for storing local variables
The HEAP is…
The heap is the block of memory in which OBJECTS reside
What does REST stand for?
Representational State Transfer
How do you run a Psake command from the powershell?
.\packages\psake.4.3.2\tools\psake.ps1 [Command] eg .\packages\psake.4.3.2\tools\psake.p21 RebuildDatabase
What does IIS stand for?
Internet Information Services
What is the S in SOLID?
Single Responsibility
What is the O in SOLID?
Open / Close Principle
What is UPCASTING?
Creating a BASE class reference from a SUBCLASS reference
eg
Cow myCow = new Cow();
Animal animal = cow; //Upcast
//**animal can only use the methods/properties available to Animal but would take anything across from myCow**//
What is DOWNCASTING?
Creating a SUBCLASS reference from a BASE class reference
eg
Animal myAnimal = new Animal();
Cow myCow = (Cow) myAnimal;
What does the ‘as’ operator do?
It performs a DOWNCAST but will return null if the downcast fails
eg
Animal myAnimal = new Animal();
Cow myCow = myAnimal as Cow;
this can be followed with an !=null check to confirm the type
What does the ‘is’ operator do?
It checks whether an object is of a certain type
eg
if (myAnimal is Cow)
{……}
/**Cow would be a type eg Cow myCow = new Cow(); **/
Is GOLD PLATING a GOOD thing or a BAD thing? Why?
It’s viewed as a BAD thing as it represents work / development that was not requested and is therefore wasteful
What is the difference between CONST and READ ONLY?
- CONST must be declared and initialised on compile, READ ONLY can be initialised during the run time, but once the value has been set it can’t be changed
So within an object, you can have different values set for each instance of the object, but any CONST values would be the same across them all.
NB: Both are static
What are the differences between Abstracation and Encapsulation?
Abstraction:
- Abstraction is a concept of hiding mechanism.
- Only showing those parts which are necessary.
- It is a thought process used in design level.
Encapsulation:
- Encapsulation is the implementation of that concept.
- Hiding complexity.
- Here it is the actual process of hiding the ‘mechanics’ of the class.
How do you convert the following the following method so that the CheckUserName method is run to asynchronously?
private void Login(name)
{
if (CheckUserName(name))
{
MessageBox.Show(“Name Ok”);
};
}
private async Task LoginAsync(name)
{
var result = await Task.Run(() => CheckUserName(name));
if (result)
{
MessageBox.Show(“Name Ok”);
}
}
Convert the following task to ASYNC:
private bool IsValidUser(name)
{
if(IsInTheDatabase(name))
{
return true;
}
return false;
}
private async Task IsValidUser(name)
{
var check = await IsInTheDatabase(name);
return check.result;
}
Convert the following to async:
public ActionResult Index()
{
using (var db = new AriaDBContext())
{
var query = db.GetAllUsers();
return View(“Index”, query);
}
}
public async Task Index()
{
using (var db = new AriaDBContext())
{
var query = await db.GetAllUsers();
return View(“Index”, query.result);
}
}
In Visual Studio, how can you quickly see the list of parameters expected within a method call?
Ctrl + Space
What is Abstraction?
It’s an OOP principle where we show only necessary things to the consumer.
If you have a static class, when do you need to instantiate it and how many instances can you instantiate?
This is a trick question, you don’t need to instantiate a static class, it’s always available. However because of this you can only ever have one ‘instance’ of it available. The contents of which remains static across the application.
However, it’s worth noting that although the variables and methods within the static object don’t change, it can still return different values (including different objects and instances of objects) from it’s methods
Lazy Loading
Lazy Loading :- This is a creational design pattern where we load objects only when we need it. The opposite of Lazy loading is eager loading.