think with java

35
Think With Java Mapping Real World Object with Java

Upload: arif-rahman

Post on 22-Jan-2017

148 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Think with java

Think With Java Mapping Real World Object with Java

Page 2: Think with java

A Society ( Group of families)

Page 3: Think with java

A Society ( Group of families)Everything in the World is an Object (Society, Family, Human, Cat, Dog, Car, River)

A society is a group of families.Families are collections of Family member.

Each Family member is Human or Non Human.

Each family member has some responsibilities (Activity) and they have their own properties.

Family members are interconnected to each other.

Page 4: Think with java

A Society ( Group of families)Each member is a human or non human.Human beings are persons.Each Human has common behavior comes from Animal.

Each family member uses their guardians vehicle or their own.

Each and every Human being has their own Address.

Page 5: Think with java

Humans(Objects) Behavior

Object is an entity which has State: determined by the values of its properties.

Behavior: determined by how an object performs an activity.

Page 6: Think with java

Humans(Objects) Properties & Behavior/ActivityEvery human(Male / Female / Other) has common properties and also they have their Behavior.

Properties: Name, Head, Hands, Hair, Eyes(color , size), Nose, Address.

Behavior: Walking, Running, Playing, Gaining Knowledge, Talking.

Page 7: Think with java

Map Now the Real World Objects

Page 8: Think with java

Java Class or Java BeanA simple Object instance container.It has some properties and behavior.So we can map our real world objects through Java .

Properties: nationalId, name, Address, vehicle,

PassportInfo, Occupation

Behavior: Walking, Running, Shopping,

Talking, Cycling,Driving

Page 9: Think with java

Access Modifier in java for properties and behaviorPublic: A declaration that is accessible to all classes with keyword “public”

Private: A declaration that is accessible only to the class in which it is declared with “private”.

Page 10: Think with java

Access Modifier in java for properties and behavior

Page 11: Think with java

Java OOP feature(Abstraction)

Customer should know to buy something

BillingStaff should know products pricing and to generate bill.

Administrator should product sell and to buy new products to gain business goal and to manage everything in the system.

ABSTRACTION: concept of identifying the essential details to be known and ignoring the non-essential details from the perspective of the end user.

Retail Shop Scenario

Page 12: Think with java

A simple Shopping Scenarioof Abstraction

Page 13: Think with java

EncapsulationThe Student don’t have to know the calculation mechanism of Calculator.

He/she just know its use of button. ENCAPSULATION: concept of hiding the

internal details and providing a simple interface to the end user which ensures that the system can be used without having to know how it works.

Page 14: Think with java

A Calculator Scenarioof Encapsulation

Page 15: Think with java

InheritanceEach Human have some common behavior of Animal.

Every family members are human or non-human(Cat or dog).

Each Regular or Privileged Customer have common Properties.

Page 16: Think with java

Different Inheritance

Page 17: Think with java

Inheritance

Allows to define the generalized and specialized characteristics and behavior. Multiple Inheritance

Page 18: Think with java

Inheritance

Allows to define the generalized and specialized characteristics and behavior.

Multi level Inheritance

Page 19: Think with java

Polymorphism Let us revisit the payment activity in the retail

shop Paymlent of bill can be done in two modes Cash(Calculation includes VAT) totalAmount = purchaseAmount + VAT Credit Card(Calculation includes processing

charge and VAT) totalAmount = purchaseAmount + VAT+

processingCharge POLYMORPHISM: concept which allows on

objecct/operation to behave differently in different situations.

So ? Now it is payment(processingCharge) or payment()?

Page 20: Think with java

PolymorphismPolymorphism is the capability of a method to do different things based on the object that it is acting upon

Following concepts demonstrate different types of polymorphism in java.

1) Method Overloading

2) Method Overriding

Page 21: Think with java

Static Binding vs Dynamic Bindingdifference between static and dynamic binding in Java.

Static binding happens at compile-time while dynamic binding happens at runtime.

Binding of private, static and final methods always happen at compile time since these methods cannot be overridden. Binding of overridden methods happen at runtime.

Java uses static binding for overloaded methods and dynamic binding for overridden methods.

Page 22: Think with java

Dynamic Polymorphism(dynamic binding) example

Page 23: Think with java

Abstract class & abstract Method

If you declare an abstract method (discussed below) in a class then you must declare the class abstract as well. you can’t have abstract method in a non-abstract class.

Page 24: Think with java

What is an interface

Interface looks like class but it is not a class. An interface can have methods and variables just like the class but the methods declared in interface are by default abstract (only method signature, no body). Also, the variables declared in an interface are public, static & final by default.

** java programming language does not support multiple inheritance (we can do this through Interface)

Page 25: Think with java

Interface and abstractInterface provides complete abstraction as none of its methods can have body. On the other hand, abstract class provides partial abstraction as it can have abstract and concrete(methods with body) methods both.

Page 26: Think with java

Use of Interface

Page 27: Think with java

Use of Interface with “abstract” keyword

Page 28: Think with java

Relationship in Java classes

Is A (Inheritance)Has A (Aggregation) Tightly coupledUses (Association) Loosely coupled

Page 29: Think with java

Relationship in Java classes

Page 30: Think with java

What next. . . . . . ORM = Object Relational MappingORM Providers : JPA, Hibernate, Spring, OFBiz

MVC = Model View ControllerMVC provider : JSF, Hibernate, Spring, OFBiz etc.

Page 31: Think with java

A Strong Tool : Collection Framework

To work with data in the local machine or memory must use the collection framework.

Collections--> Set, List, ArrayList, Map, LinkedHashMap

Page 32: Think with java

Collection Framework overview.

Page 33: Think with java

Collections Example

Page 34: Think with java

Questions & Answers Fun with Java :)

Page 35: Think with java

Thanks to all…Md. Arifur RahmanJunior Software Engineer,Newgen Technology Limited, Bangladesh.