OOP, API Design and MVP
Upcoming SlideShare
Loading in...5
×
 

OOP, API Design and MVP

on

  • 400 views

Presentation on the principles, philosophy and a few applications of object oriented programming along with a few pointers on how to effectively code. Presented at a session aimed at undergrad ...

Presentation on the principles, philosophy and a few applications of object oriented programming along with a few pointers on how to effectively code. Presented at a session aimed at undergrad computer science students at the University of Pune.
Present along with Mr. Anirudh Tomer and Mr. Toshish Jawale.

Statistics

Views

Total Views
400
Views on SlideShare
400
Embed Views
0

Actions

Likes
0
Downloads
2
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

OOP, API Design and MVP OOP, API Design and MVP Presentation Transcript

  • SOLID OOPSConvertingReal world entities into programming Objects ; understanding its applications ; API designing, MVC framework
  •  We apologize for wrong session title  Lets know each other Your expectations Our aim Why should you join this session Goodies for active participants Introduction
  •  What is “Real”? Everything outside of your program is Real. Even your own program is a Real World Entity for some other program or even for your own program! In shortReal World Entity… View slide
  •  Because these are all the “things” on which we want to work upon. Yes, and by work we do not mean, just writing the code! Why do we bother about this? View slide
  •  Objects? Why? How are they introduced in the programming world? Where are they used often? State and behaviour Who should use it?Correlating to programmingobjects
  •  We separate our real world entities in different groups Object is an instance of a class Ball instances ofWhat is this class?
  •  How classes are organized? Why classes need to be organized? Is there any standard way to do it? If yes, whats it?Organization
  •  How these different attributes of a class are defined? fields/properties - state methods/functions - behavior constructors/initializers destructorsWhat class contains?
  •  What is the object oriented way of getting rich ? — Inheritance Relations between the classes By the way, are you good at relations?Relations
  •  Have you watched Television?Interface
  •  Something you use to keep your stuff from mixing together Folders Drives A customized, more sophisticated package Examples familiar to you are, ◦ ZIP file ◦ EXE file ◦ DLL file etc.Point is, keep your stuff organized.Package
  • What is Abstraction?• Abstraction - a concept or idea not associated with any specific instance• It is all about perspective
  • Where does abstraction exist?• Control abstraction o Abstraction of actions• Data abstraction o Abstraction of information
  • How does this relate toprogramming?• Writing functions/subroutines is control abstraction.• Datatypes is data abstraction.
  • Data Abstraction• Generalization• Specialization
  • Examplepublic class Animal extends LivingThing{ theChicken = new Animal(); private Location loc; theCat = new Animal();if private double energyReserves; (theChicken.isHungry()) public boolean isHungry() { { return energyReserves < 2.5; theChicken.eat(grains);} } if (theCat.isHungry()) { public void eat(Food f) { theCat.eat(mouse);} // Consume food theCat.moveTo(theSofa); energyReserves += f.getCalories(); } public void moveTo(Location l) { // Move to new location loc = l; }}
  • Its relevance with OOP• Object is an attempt to combine data and control abstraction• Polymorphism• Inheritence
  • Why do this?• Separate the business logic from the underlying complexity• Make it easier to parallelize tasks• Meaningful amount of details are exposed• Representation in a similar form in semantics (meaning) while hiding implementation details.
  • Why do we write programs?
  • We have the right objects inplace, now what?• Lets get them talking to each other• Lets actually tell them what to talk about
  • What sort of messages?• Creation• Invocation• Destruction
  • Who generates thesemessages?• Aliens? • Platform• The Government? • User Interaction • Events
  • API Designing
  • String operations I need it to be Hehehe! The menu driven whole 2 hours I will just write a fancy menu Programming Lab I
  • Set operations Again! *$%#@ I need it to be Menu will be menu driven “Enter 1 to proceed 0 to exit” Programming Lab I
  • Don’ts we do Monolithic programs Single file containing all functions Code repetition Thinking less about function signature Reinventing the wheel
  • What we think about API  API
  • What it actually is  printf(), scanf(), strcmp() Easy to use and hard to misuse Spec of DS, functions, Can be programming language unspecific!! behavior etc. Not necessarily a code library, can be just a spec You can create your own API too
  • Lets design an API
  • Designing Process (based on suggestions by Joshua Bloch) Write 2 programs and not one Write API first ◦ Understand the use case ◦ Foresee future extensions (don’t change API often) ◦ A general purpose API vs multiple small API’s ◦ If you can’t name it, its doing either extra or doing less ◦ Don’t surprise the API user, don’t do extra ◦ Remember! You can always add but you can’t remove ◦ Document the API religiously! ◦ Use consistent parameter ordering. ◦ Extra params, use a struct Code more! API is living thing Expect to make mistakes. Refactor API! Encourage others to use it
  • MVC Architecture
  • Programming without MVC I need it Linked List with GUI o add a node o remove a node o reverse a linked list Linked list with GUI ______ ______ ______|__1__| |__5__| |__7__| …
  • Challenges Data Functions GUI Structures • Function • Creating • struct ? signature boxes • Separate • Flow control • Moving variables boxes
  • Nightmare beginstypedef struct node{ struct node* nextNode;…}Node;…Node *linkedlist;addNewNode(){ while (linkedlist->nextNode!=null){ drawSquare(); //you may have internal D.S. for each square drawArrow(); } Node *newNode = (Node*) malloc(sizeof(struct node)); scanf(); // for new values newNode->val1 = …; newNode->val2 = …; linkedlist->nextNode = newNode; while (linkedlist->nextNode!=null){ drawSquare(); drawArrow(); }}
  • New requirements Keep different colors for each node I want oval nodes not rectangular nodes I want linked list nodes to be shown in hierarchy not in straight line. Make Changes
  • FB Timeline: Full of GUIComponents
  • MVC Framework: Coding vs.Architecting Its nothing but how you design your code.
  • Model View Controller• Handling data • Display data • Read data• Save them on from view file or in • Control user internal D.S interaction • Send new data to modelRoles: Model, View and Controller
  • M-V-C not MVC Keep them separate You may create different files ◦ A separate “model.h” ◦ A separate “view.c” (includes model.h) ◦ A separate “controller.c” (includes model.h) ◦ Give deep thought to data structures Principle of Agnosticism: each component is unaware of others presence
  • Modeltypedef struct node{ C++ or other struct node* nextNode; int id; OOP languages … make finding the}Node;int globalId = 0; context easytypedef struct linkedList{ Node * headNode; int id; int listLength;}LinkedList;LinkedList *linkedListPool[];void addNode(int linkedListId, int index, Node *newNode){ …}void removeNode(int linkedListId, Node *node){ …}LinkedList* createNewLinkedList(){ LinkedList* newll = (LinkedList*) malloc(sizeof(struct linkedList)); newll->id = globalId++; newll->headNode = (Node*) malloc(sizeof(struct node)); newll->length = 0; linkedListPool[globalId] = newll; return newll;}
  • Viewtypedef struct viewNode{ struct viewNode* nextViewNode; int xLocation, int yLocation; String color; //#FF3e2A (in hex)…}ViewNode;//Similar to Model create another structtypedef struct display{ ViewNode* head; int id; int length;}Display;Display *displayNodeList[];void addDisplayNode(int viewNodeId, int index, Node *newNode){ //create new ViewNode //Render UI …}//create new display node like Model
  • Controllertypedef enum input{ ADD,REMOVE,GET_LENGTH…}Input;LinkedList* linkedList = createNewLinkedList();Display* display = createNewDisplay();//Show a fancy menuInput input = read input from user;switch(input){ case ADD: Node* newNode = //malloc new node; addNode(linkedList->id,newNode); addDisplayNode(display->id,newNode); break;}
  • Questions ?