Skip to content

Instantly share code, notes, and snippets.

View CaglarGonul's full-sized avatar

ccocoo CaglarGonul

View GitHub Profile
@CaglarGonul
CaglarGonul / 01.Beverage.java
Last active December 24, 2015 00:09
Beverage class which holds the abstract information of a beverage.
package com.v1;
import java.util.ArrayList;
import java.util.List;
public abstract class Beverage {
String description ;
List<ICondiment> condiments = new ArrayList<ICondiment>();
public void addCondiment(ICondiment condiment){
@CaglarGonul
CaglarGonul / SimpleWS.java
Created May 4, 2013 13:38
A simple web service implementation.
package org.example.simplecalculationsservice;
import java.util.logging.Logger;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlSeeAlso;
@CaglarGonul
CaglarGonul / cl.c
Created April 11, 2013 19:55
From Dan Grossman course. How to use closures in C.
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
typedef struct List list_t;
struct List {
void * head;
list_t * tail;
};
list_t * makelist (void * x, list_t * xs) {
@CaglarGonul
CaglarGonul / 1. CallBack.java
Created April 10, 2013 14:42
This time I understood what a closure is...
package com.fs;
public interface CallBack {
void m(int e);
}
@CaglarGonul
CaglarGonul / 1. Subject.java
Created April 8, 2013 13:20
A built in observer pattern. It seems it is no different than my callback implementation in Java
package com.chp2.observerpattern.custom;
/**
* The objects who will broadcast events will implement this interface
*/
public interface Subject {
public void registerObserver(Observer o);
public void removeObserver(Observer o);
public void notifyObservers();
}
@CaglarGonul
CaglarGonul / 1.WeaponBehaviour.java
Last active December 15, 2015 21:29
The Strategy Pattern : It defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
package com.chp1.designpuzzle;
public interface WeaponBehaviour {
String useWeapon();
}
@CaglarGonul
CaglarGonul / 1.Animal.java
Created April 6, 2013 08:43
Programming to an interface rather than an implementation.
package com.chp1.simuduck.v3;
public interface Animal {
void makeSound();
}
@CaglarGonul
CaglarGonul / 1.CallBack.java
Last active December 15, 2015 20:49
Callback implementation in Java7
package com.fs;
public interface CallBack {
void m(int e);
}
@CaglarGonul
CaglarGonul / 1.Func.java
Last active December 15, 2015 20:48
Playing with closures in Java7. Thanks to Prof. Grossman.
package com.fs;
/**
* This interface is responsible for holding the closures when it comes to map.
* It uses two generic types. One for the argument and one for the return type.
* @param <B> Generic type
* @param <A> Generic type
*/
public interface Func<B,A> {
/**
@CaglarGonul
CaglarGonul / mycb.sml
Last active December 15, 2015 17:19
A callback implementation in ML.
(*We need a mutable list to store the list of registered callbacks.*)
(*The initial list will be empty.*)
val cbs : (int -> unit) list ref = ref []
(*We need a public function to register the callbacks on the the callback list*)
fun registerCallBack f =
cbs := f::(!cbs)
(*When a specific action occurs we will call this function.*)
(*This function will call each call back with a parameter.*)