002_a_pemrograman berorientasi object

Upload: milhcbt1790

Post on 09-Apr-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    1/26

    Pemrograman Berorientasi

    Object

    Introduction to class and object

    ImanLHakim, 2011

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    2/26

    Objectives

    Tujuan Instruksional Khusus (TIK)

    Mahasiswa mampu mengerti dan memahami konsep

    dasar dari Pemrograman Berorientasi Objek yaitu

    Abstraksi, Encapsulasi, Modularity dan Hierarki. Pokok Bahasan

    Konseptual Objek Model

    Sub Pokok Bahasan Konseptual Objek Model (Abstraksi dan Encapsulasi)

    Konseptual Objek Model (Modularitas,Hierarki)

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    3/26

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    4/26

    Programmings Abstraction

    1. Procedure-oriented Algorithms

    2. Object-oriented Classes and objects

    3. Logic-oriented Goals, often expressed in a predicate

    calculus

    4. Rule-oriented Ifthen rules

    5. Constraint-oriented Invariant relationships

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    5/26

    Four major elements of O-O

    Model without any one of these elements is not

    object-oriented.

    Abstraction

    Encapsulation

    Modularity

    Hierarchy

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    6/26

    Three minor elements of the object

    model

    Each of these elements is a useful, but not

    essential, part of the object model

    Typing

    Concurrency

    Persistence

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    7/26

    Abstraction

    Abstraction focuses on the essential

    characteristics of some object,

    relative to the perspective of the

    viewer

    Entity abstraction An object that represents a useful

    model of a problem domain or

    solution domain entity

    Action abstraction

    An object that provides a

    generalized set of

    operations, all of which perform the

    same

    kind of function

    Virtual machine

    abstraction

    An object that groups operations

    that are all

    used by some superior level ofcontrol, or

    operations that all use some junior-

    level set

    of operations

    Coincidental

    abstraction

    An object that packages a set of

    operations

    that have no relation to each other

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    8/26

    Encapsulation

    Encapsulation hides the

    details of the

    implementation of an

    object

    Encapsulation is the process of

    compartmentalizing the elements of anabstraction that constitute its structure and

    behavior; encapsulation serves to separate the

    contractual interface of an abstraction and its

    implementation

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    9/26

    Modularity

    Modularity packages abstractions into discrete units.

    Modularity is the property of a system that has

    been decomposed into a set of

    cohesive and loosely coupled modules

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    10/26

    Hierarchy

    Hierarchy is a ranking or orderingof abstractions.

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    11/26

    Typing

    Typing is the enforcement of the class of anobject, such that objects of different

    types may not be interchanged, or at the

    most, they may be interchanged only in

    very restricted ways.

    Function.prototype.StName = function () {

    var st;st = this.toString();

    return st;

    }

    String StName (){

    String st;

    st = this.toString()return st

    }

    String StName (){

    Object st;

    st = this.toString()

    return (String) st

    }

    String StName (){

    int st;

    st = this.toString()

    return st

    }

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    12/26

    Concurrency

    Concurrency allows different objects to act at

    the same time

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    13/26

    Persistence

    Persistence saves the state and class of an

    object across time or space

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    14/26

    Object ?

    An object is an entity that has state, behavior, and identity. The

    structure and behavior of similar objects are defined in their common

    class. The terms instance and object are interchangeable.

    The state of an object

    encompasses all of the (usually

    static) properties of the object

    plus the current (usually dynamic)

    values of each of these properties.

    Behavior is how an object acts andreacts, in terms of its state changes

    and message passing.

    Identity is that property of an

    object which distinguishes it from

    all other objects

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    15/26

    Relationships among Objects

    Links, physical or conceptual connection between objects

    Aggregation, denotes a whole/part hierarchy, with theability to navigate from the whole (also called theaggregate) to its parts

    Aggregation is sometimes better because it encapsulates partsas secrets of the whole. Links are

    sometimes better because they permit looser coupling amongobjects

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    16/26

    Class

    A class is a set of objects that share a common structure, common behavior, and

    common semantics

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    17/26

    Class: Interface vs Implementation

    A Class may has Interface and Implementation

    The interface of a class provides its outside view and therefore emphasizes the

    abstraction while hiding its structure and the secrets of its behavior.

    The implementation of a class primarily consists of the implementation of all

    of the operations defined in the interface of the class.

    // Student.cpp

    // Implementation of the Class Student

    #include "Student.h"

    Student::Student(){

    }

    Student::~Student(){

    }

    boolean Student::cheating(char* bookTitle){

    return NULL;

    }

    void Student::cheating(){

    }

    // Student.h

    // Interface of the Class Student

    class Student

    {

    public:

    int age;

    char* name;Student();

    virtual ~Student();

    boolean cheating(char* bookTitle);

    private:

    void cheating();

    };

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    18/26

    Class Relationships

    Association

    Inheritance (is a) Single Inheritance

    Polymorphism

    Multiple Inheritance

    Aggregation (part of) containment by

    value.

    containment byreference.(composition)

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    19/26

    Language Feature vs Concepts

    C++class TempControl

    {

    public:

    Heater m_Heater;

    Termometer *m_Termometer;

    };

    Javapublic class TempControl {

    public Heater m_Heater;

    public Termometer m_Termometer;

    }

    No Differences in Java

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    20/26

    Sample relationship in microsoft COM

    Model Use for

    Inheritance Exposing the managed object

    as the outer object.

    Aggregation Enabling the outer object to

    expose another object's

    implementation of an interface

    without modification.

    Containment Enabling the outer object tomodify the behavior of the

    inner object.

    http://msdn.microsoft.com/en-us/library/k3k086s0(VS.71).aspxhttp://msdn.microsoft.com/en-us/library/k3k086s0(VS.71).aspxhttp://msdn.microsoft.com/en-us/library/k3k086s0(VS.71).aspxhttp://msdn.microsoft.com/en-us/library/k3k086s0(VS.71).aspxhttp://msdn.microsoft.com/en-us/library/k3k086s0(VS.71).aspxhttp://msdn.microsoft.com/en-us/library/k3k086s0(VS.71).aspx
  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    21/26

    On Building Quality Classes and

    Objects Coupling,

    the measure of the strength of association established by a connection fromone module to another.

    Strong coupling complicates a system since a module is harder to understand,change, or correct by itself if it is highly interrelated with other modules

    Cohesion Cohesion measures the degree of connectivity among the elements of a single

    module (and for object-oriented design, a single class or object)

    Sufficiency the class or module captures enough characteristics of the abstraction to

    permit meaningful and efficient interaction.

    Completeness the interface of the class or module captures all of the meaningful

    characteristics of the abstraction

    Primitiveness Very Simple, basic

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    22/26

    Classification

    Classical categorization ( common property)

    Conceptual clustering (meet concept)

    Prototype theory

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    23/26

    Candidates of class

    Shlaer and Mellor

    Tangible things: Cars, telemetry data, pressure

    sensors

    Roles: Mother, teacher, politician

    Events: Landing, interrupt, request

    Interactions: Loan, meeting, intersection

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    24/26

    Candidates of class

    Ross

    People: Humans who carry out some function

    Places : Areas set aside for people or things

    Things : Physical objects, or groups of objects, that are Tangible

    Organizations: Formally organized collections of people, resources,facilities, and capabilities having a defined mission, whose existenceis largely independent of individuals

    Concepts: Principles or ideas not tangible per se; used to organizeor keep track of business activities and/or communications

    Events: Things that happen, usually to something else at a

    given date and time, or as steps in an ordered sequence

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    25/26

    Coad Yourdon

    StructureIs a and part of relationships

    Other systems External systems with which the applicationinteracts

    Devices Devices with which the application interacts Events remembered A historical event that must be

    recorded

    Roles played The different roles users play in interactingwith theapplication

    Locations Physical locations, offices, and sites important tothe application

    Organizational units Groups to which users belong

  • 8/7/2019 002_A_Pemrograman Berorientasi Object

    26/26

    Bibliography

    Booch, G., Maksimchuk, R. A., Engle, M. W.,

    Young, B. J., Conallen, J., & Houston, K. A.

    (2007). Object-Oriented Analysis and Design

    with Applications (Third ed.). Massachusetts:Addison-Wesley.