Pengenalan OOP

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

Pemrograman Lanjut

Introduksi Object-Oriented Programming

Victor Phoa, S.Si., M.Cs - @2020


Object Oriented Programming (OOP)

• OOP is a programming language that uses classes and


objects to create models based on the real world
environment.

• An OOP application may use a collection of objects which


will pass messages when called upon to request.

• Objects are able to pass, receive messages or process


information in the form of data (Class, structure, vars, etc).
Advantages of OOP

• Easy to maintain and modify existing code as new objects


are created inheriting characteristics from existing ones.

• This cuts down the development time considerably and


makes adjusting the program much simpler.

• Class or created framework can be separated


programmed and tested separately by working team.
Procedural vs Object Oriented
Procedural/Inline Programming Object Oriented Programming
Procedural Programming takes on applications Object-oriented Programming uses classes
by solving problems from the top of the code and objects, breaks that problem down into
down to the bottom. smaller sub-problems or sub-procedures.
Procedures must tightly written and integrated Separated Sub-procedures can be continually
with main application. broken down in the process called functional
decomposition until the sub-procedure is
simple enough to be solved.
if an edit is needed to the program, the Only need to changes class part or replace the
developer must edit every line of code that class with others to adapt the new behavior.
corresponds to the original change in the code.
The first major procedural programming Most widely used programming languages
languages appeared circa 1957–1964, (such as C++, Java, Python, etc.) Significant
including Fortran, ALGOL, COBOL, PL/I and object-oriented languages include Java, C++,
BASIC.Pascal and C were published circa C#, Python, PHP, JavaScript, Ruby, Perl,
1970–1972. Object Pascal, Objective-C, Dart, Swift, Scala,
Common Lisp, MATLAB, and Smalltalk.
Imagine build a single car all by yourself with
casting... (Procedural analogy)
A single car has about 30,000 parts, counting every
part down to the smallest screws created separately.
Produced independently then crafted together (OOP
Analogy)
Human Body Anatomy
A Class like
anatomy in
OOP
imports types
defined in
SelDarah
Declare a scope
that contains a set
of related objects.

You can use a


namespace to
organize code
elements and to
create globally
unique types.
Classes are
declared using the
keyword class
A method in object-
oriented programming
is a procedure
associated with a
class. A method
defines the behavior
of the objects that are
created from the class.
Another way to say
this is that a method is
an action that an
object is able to
perform.
Fields:
In object-oriented
programming, field
(also called data
member or member
variable) is the data
encapsulated within a
class or object.

Examples of other
fields: name, gender,
hair colour, etc.
C#

• We will use C# in student class and workshop.

• C# (C-Sharp) is a programming language developed by Microsoft


that runs on the .NET Framework around 2000.

• C# is used to develop web apps, desktop apps, mobile apps,


games and much more.

• Programming IDE: Visual Studio, SharpDevelop, MonoDevelop,


Xamarin Studio (Integrated with VS), Unity, Xenko, etc
Pros & Cons

• Pros:
– Easy to use.
– Self maintain Memory allocator management (Garbage Collector).
– No need to Allocate/Deallocate class or memory manually (eliminate
newcomer programmer headache from memory leaks when use C/C++).
– Development time is shorter than C++ (2-4X faster).

• Cons:
– Using Virtual Machine / JIT (similar to Java).
– Runtime not faster than native machine code apps (C++).
– Garbage Collector (GC) can cause hiccup in realtime/game apps.
– Executable can be decompiled. Your private code is not safe!
Decompiled EXE with ILSpy
Versi 5.1:
https://sourceforge.net/projects/sharpdevelop/
Pros: Lightweight, Compatible with Visual
Studio Solution/Project.

Cons: Have some bugs, No longer


developed (discontinued) since to Visual
Studio Community is available (free).
Game with C#
- 100,000+ lines of C# codes.
- 70+ Classes.
- Single developer.
- 2 years of development.

You might also like