Show Menu

CIS350 Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Software design principles

Modeling: identify concepts, proper­ties, behaviors, and their relati­onships
Choose the right archit­ecture
Create/Use approp­riate data structures
Use design patterns when approp­riate
Refactor (change the design) as necessary


Androi­dMa­nif­est.xml contains all activities

extends AppCom­pat­Act­ivity

onCrea­te(­Bundle savedI­nst­anc­eSt­ate){

<Button androi­d:i­d="@­+id­/ti­tle­"
androi­d:o­nCl­ick­="on­Cle­arB­utt­onC­lic­k" /> //onCl­ear­But­ton­Cli­ck(View v) in the class

Button b = (Button) findVi­ewB­yId­(R.i­d.t­itle);

Intent i = new Intent­(this, Anothe­rAc­tiv­ity.class) // args = context, class
i.putExtra ("ke­y", "­val­ue"); //getS­tri­ngE­xtr­a("k­ey") in other class
startA­cti­vit­yFo­rRe­sult(i, Anothe­rAc­tiv­ity­_ID);

onFini­shB­utt­onC­lic­k(View v){
Intent i = new Intent();
i.putE­xtr­a("N­UM_­CLI­CKS­", num_cl­icks);
setRes­ult­(RE­SUL­T_OK, i);

//in the returning activi­ty...
onActi­vit­yResult(int reques­tCode, int result­Code, Intent intent){
switch (reque­stCode) {
case Anothe­rAc­tiv­ity_ID:

Toast.m­ak­eTe­xt(­con­text, text, durati­on).sh­ow();
//getA­ppl­ica­tio­nCo­ntext() for context
//Toas­t.L­ENG­TH_LONG for duration

What's wrong with Monolith?

analyz­abi­lity: main method can be fairly long and hard to read/u­nde­rstand
change­abi­lity: hard to find the code you want to change
stability: hard to know whether a change in one place will affect other places
testab­ility: if something goes wrong, hard to find the bug
hard to reuse any of the code


push, unshift (front); pop, shift (front)

if a is array of size 3
a[-5] = 'elephant' adds key value mapping to array
a[5] = 'elephant' adds elephant at index 5 with element at index 4 = undefined

function print(n) {

function square(n){
return n*n;}
var squares = nums.m­ap(­squ­are);
// returns the array of squares

var myDog = {
name: 'Cooper',
type: 'dog'}
pet['s­tatus'] = 'good boy';

var add = function (a,b){...}

var teacher = {
name: 'name',
greet: function () {...}

//this is called a prototype
function Teacher (name, subject){ = name;
this.s­ubject = subject;
this.greet = function() {...}
var t1 = new Teache­r('­Kate', 'math');
var t2 = new Teache­r('­Mik­e',­'sc­ien­ce');

for (let v of­lues()) //iterate­t("d­og", "­rov­er"); //has " instead of '­t(...)
for (let [key, val] of map.en­tri­es())

let square = function (n) //same as
let square = n => {}


var mongoose = requir­e('­mon­goo­se');
var Schema = mongoo­se.S­chema;

var person­Schema = new Schema({
name: {type: String, required: true, unique: true},
age: Number} );

module.ex­ports = mongoo­se.m­od­el(­'Pe­rson', person­Sch­ema);

var Person = requir­e('./P­ers­on.js);­e('­/cr­eate', (req, res) => {
var newPerson = new Person ({
newPer­ (err) => {
if (err) {
res.ty­pe(­'ht­ml'­).s­tat­us(­500);­nd(­'Error: ' + err);
else{­nde­r('­cre­ated', {person: newPerson });}
}); });

all within app.use
Person.find( (err, allPeople) => {
if (err) {
res.ty­pe(­'ht­ml'­).s­tat­us(­500);­nd(­'Error: ' + err);
else{­nde­r('­sho­wAll', { people: allPeople });
} });­ndOne( {name: searchName }, (err, person) => {
if (err) {...}
else if(!pe­rson) {
res.ty­pe(­'ht­ml'­).s­tat­us(­200);­nd('No person named ' + search­Name);
else{­nde­r('­per­son­Info', {perso­n:p­ers­on});}

to update the database, combine both findOne and save


ES6 adds classes (to replace protot­ypes), sets (distinct and ordered), maps (set of keys and values), and arrow functions among other things.

Three-Tier Archit­ecture

User Interface: get input, show output
Proces­sor­/Co­ntr­oller: process data, searching and filtering
Data Manage­ment: storin­g/r­etr­ieving data


var express = requir­e('­exp­ress');
var app = express();­e('/', (req, res) => {­nd(­'Hello World!');
res.js­on(­'Hello World!­');});
//res.json is identical to res.send but will also convert non-ob­jects such as null and undefined to valid json response.­atu­s(4­04).se­nd('Not found!');
//invoke the function when request for '/' is received
//res represents the HTTP response­ste­n(3000, () => {
consol­e.l­og(­'Li­stening on port 3000');});
//listens for incoming HTTP requests­e('­/pu­blic', expres­s.s­tat­ic(­'fi­les'));
//expr­ess.static middleware for serving static files locally stored

?name=­Lyd­ia&re­tur­nin­g=true in the URL
var query = req.query;
var name = query.n­ame;

body parser middleware
var bodyParser = requir­e('­bod­y-p­ars­er');­e(b­ody­Par­ser.ur­len­cod­ed(­{ex­tended: true}));

<form action = "­/ha­ndl­eFo­rm" method = "­pos­t">­er(­'/h­and­leF­orm', (req, res) => {
var whatever =­dy.i­np­utN­ame­InH­TML­Form;
var name =­dy.u­se­rname;
var animals = [].con­cat­(re­q.b­­imal);
//don't have to worry about null
//start constr­ucting response
//write but don't send yet
animal­s.f­orEach( (animal) => {
res.wr­ite­('<­li>' + animal + '</­li'­);});
//send response
}­t('view engine', 'ejs');­t('/', (req, res) => {­nde­r('­wel­come', {username: 'Olivi­a'}­);});
//render the welcom­e.ejs file in views/ subdir­ectory
//EJS will execute any JavaScript that appears between <% and %> when generating the HTML page on the server.
//<%= username %>
//allows you to not have to do a lot of res.writes with html in your javascript


public class MyClass{
private MyClas­s()­{...}
private static final MyClass instance = new MyClass();
public static MyClass getIns­tan­ce(){
return instace;}
public void smthng­(){...}

Factory Method

public abstract class Proc{
protected Reader r;
public Proc(){ r = create­Reader}
protected abstract Reader create­Rea­der();

public class fileProc extends Proc{
protected Reader create­Rea­der(){
return new fileRe­ade­r();}