Skip to content

Instantly share code, notes, and snippets.

@SriMaddy
SriMaddy / poodr - ch 1
Created April 21, 2015 19:40
Practical OOD in Ruby : Addison - Wesley
1) World is Procedural : sequence of actions like human is getting up, taking bath, going office, return home
2) World is also Object oriented : interacting with people : spouse_step_on_cat (heart beat increses for cat and also for spouse)
3) OOD takes us to collection of predefined procedures to messages passing between objects
4) How to learn OOD : Immerse yourself in objects
5) Software is being built for reason like hospital management, games, etc.
6) If we dont need to change design not matters but changes are unavaidable
7) Why change is hard: having more dependency, not proper designed coding
8) SOLID : Single responsibility, Open-Closed, Liskov Substitution, Interface Segregation, Dependency Inversion
9) DRY - Dont Repeat Yourself and Law of Demeter
10) How design fails : due to less designed code which can add feature but it will break everything on other hands, can not add feature as it was not designed to do that
@SriMaddy
SriMaddy / poodr - ch 3
Last active August 29, 2015 14:19
Practical OOD in Ruby : Addison - Wesley
Recognize Dependency :
-> A class has another class
-> calls method in another class
-> Args that message(method) requires. Gear knows Wheel.new
requires rim and tire as well as order of Args.
More coupling -> More dependency
Tightly coupled two objects act as single entity
Avoid message chaining on different objects
If you cannot remove dependency from class just isolate them.
@SriMaddy
SriMaddy / poodr - ch 2
Created April 25, 2015 04:12
ractical OOD in Ruby : Addison - Wesley
Class : Doing possible smallest thing
Change :
-> no side effects
-> small change in requirement require small change in code
-> existing code should be easy to reuse
-> add code that in itself must be easy to change further
TRUE princliple
High cohesion : High single ersposibility
Depend on behaviour not on data.
Hide Data Structures(cell[0]: rim, cell[1]: tire)
@SriMaddy
SriMaddy / poodr - ch 4
Created April 25, 2015 13:23
Practical OOD in Ruby : Addison - Wesley
Interface : method inside class which should be communicate with other objects with clear message pattern.
Ex : Kitchen
-> serve() is necessary but cookingManner() is not necessary.
-> Make them appropriate private or public interfaces
Use UML, Sequence diagram
Ask for what not for how
Reduce Law of demeter(Message chaining)
@SriMaddy
SriMaddy / poodr - ch 5
Created April 26, 2015 12:20
Practical OOD in Ruby : Addison - Wesley
Duck Typing :
-> Abstract class / interface
-> To make code to be easy to change
-> increases flexibitlity
Statically Typing VS Dynamically Typing
Meta Programming : Writing code that writes code
@SriMaddy
SriMaddy / poodr - ch 6
Created April 27, 2015 08:42
Practical OOD in Ruby : Addison - Wesley
Classical inheritance :
Message delegation to another object if one object is not respond to message.
-> find abstraction and create abstract class.
-> Unresponsed messages are automatically delegated(forwarded) to its super class and so on.
-> light weight framework used to build any type of java apps
-> its non-invasive : does not force a programmer to extend any predefined class (like struts)
-> features :
-> simplicity (non-invasive)
-> testability (no need server/container)
-> lightly coupling
-> modules in spring 1.x :
-> core module
-> context module (J2EE)
-> HTTP request are handled by controller.
-> @RestController over class
-> @RequestMapping("/path", METHOD=GET/POST....) over method
-> @RequestParam(value="name", defaultValue="Some Default Values") : these are query string params in url/ by default its set to required = false
-> java.util.concurrent.atomic.AtmoicLong is counter which returns specified Rest Object
-> Now converting object to JSON by MappingJackson2HttpConverter which is inside spring's Jackson2.
-> No SQL (Non-Relational, full of documents)
-> Database - Database, Table - Collection, Tuple - Document, column - field, table join - document embed
-> unique id for every object
-> id will be 12 byte hex, 4 = timestamp, 3 = machine id, 2 = process id of mongo server, 3 = incremental value
@SriMaddy
SriMaddy / volley_https.txt
Last active March 29, 2017 05:26
https call via volley
⁠⁠⁠public void NetworkCall() {
RequestQueue queue;
StringRequest stringRequest;
queue = Volley.newRequestQueue(getApplicationContext(),new HurlStack(null, createSslSocketFactory()));
stringRequest = new StringRequest(Request.Method.POST, "https://www.thehellofood.com/restaurantapi/getFoodItems", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
Log.e("response", response);
} catch (Exception e) {