You are on page 1of 4

together without specifying their concrete

classes.
• When there are interrelated dependencies with
not-that-simple creation logic involved
• Builder

Rangkuman Ad- • Allows you to create different flavors of an

prog
object while avoiding constructor pollu-
tion. Useful when there could be several flavors
of an object. Or when there are a lot of steps
involved in creation of an object.
• When there could be several flavors of an ob-
Ahmad Satryaji Aulia ject and to avoid the constructor telescoping.
The key difference from the factory pattern is
Design Patterns (Ch. 1, 2, that; factory pattern is to be used when the cre-

3, 4, 5)

ation is a one step process while builder pattern


is to be used when the creation is a multi step
process.
• Prototype
Design patterns are solutions to recurring prob-
lems; guidelines on how to tackle certain • Create object based on an existing object
problems. They are not classes, packages or li- through cloning.
braries that you can plug into your application and • When an object is required that is similar to ex-
wait for the magic to happen. These are, rather, isting object or when the creation would be ex-
guidelines on how to tackle certain problems in pensive as compared to cloning.
certain situations. • Singleton
• Ensures that only one object of a particular
Creational Design Patterns
class is ever created.
• Kalo lazy instantiation, dia di taro di , kalo ea-
ger instantiation di constructor.
Creational patterns are focused towards how to in-
stantiate an object or group of related objects.
Structural Design Patterns

• Simple Factory
• Simple factory simply generates an instance Structural patterns are mostly concerned with ob-
for client without exposing any instantia- ject composition or in other words how the entities
tion logic to the client can use each other. Or yet another explanation
• When creating an object is not just a few as- would be, they help in answering "How to build a
signments and involves some logic, it makes software component?"
sense to put it in a dedicated factory instead of
repeating the same code everywhere. • Adapter
• Factory Method • Adapter pattern lets you wrap an otherwise
• It provides a way to delegate the instantia- incompatible object in an adapter to make
tion logic to child classes. it compatible with another class.
• Useful when there is some generic processing in • Bridge
a class but the required sub-class is dynamically
• Bridge pattern is about preferring composi-
decided at runtime. Or putting it in other
tion over inheritance.
words, when the client doesn't know what exact
• Implementation details are pushed from a hier-
sub-class it might need.
archy to another object with a separate hierar-
• Abstract Factory chy.
• A factory of factories; a factory that groups • Composite
the individual but related/dependent factories

1
• Composite pattern lets clients treat the individ- helps reduce the coupling between the classes
ual objects in a uniform manner. communicating with each other. Because now
• Semua objek punya fungsi-fungsi yang they don't need to have the knowledge of each
sama. other's implementation.
• Decorator • Memento
• Decorator pattern lets you dynamically change • Memento pattern is about capturing and
the behavior of an object at run time by storing the current state of an object in a
wrapping them in an object of a decorator class. manner that it can be restored later on in a
• Misal smooth manner.
• Facade • Observer
• Facade pattern provides a simplified inter- • Defines a dependency between objects so that
face to a complex subsystem. whenever an object changes its state, all its
• Misalnya padahal musti , dll. dependents are notified.
• Flyweight • Visitor
• It is used to minimize memory usage or compu- • Visitor pattern lets you add further opera-
tational expenses by sharing as much as pos- tions to objects without having to modify
sible with similar objects. them.
• Proxy • Strategy
• Using the proxy pattern, a class represents • Strategy pattern allows you to switch the al-
the functionality of another class. gorithm or strategy based upon the situa-
tion.

Behavioral Design Patterns


• State
• It lets you change the behavior of a class
when the state changes.
Behavioral design patterns are design patterns that • Misalnya terus
identify common communication patterns between • Template Method
objects and realize these patterns. By doing so, • Template method defines the skeleton of
these patterns increase flexibility in carrying out how a certain algorithm could be performed,
this communication. but defers the implementation of those
steps to the children classes.
• Chain of Responsibility
• It helps building a chain of objects. Request
enters from one end and keeps going from Refactoring, Code Smells
object to object till it finds the suitable handler. (Ch. 6)

• Command
• Allows you to encapsulate actions in ob-
jects. The key idea behind this pattern is to Refactoring: Improving a piece of software's in-
provide the means to decouple client from re- ternal structure without altering its external behav-
ceiver. ior.
• Misalnya
Why refactor?
• Iterator
• It presents a way to access the elements of • Improves the design of software
an object without exposing the underlying • Code is easier to understand
presentation. • To find bugs
• Mediator • To make the program faster.
• Mediator pattern adds a third party object
(called mediator) to control the interaction When to refactor?
between two objects (called colleagues). It

2
• When you add a function
• When you need to fix a bug
Declarative Programming
• Code isn't thoroughly tested, but seems to work (Ch. 8)

so far

Code Smells  

Contoh declarative programming:

newList = startList.filter(num -> num%2


==1)''

• Higher order function:


• Fungsi yang menerima fungsi lain sebagai argu-
  ment
• Misalnya fungsi sort menerima aturan sorting
berupa fungsi pembanding
• Favor immutability:
• Variable tidak mutable, tidak bisa diubah. Varia-
ble merupakan binding terhadap value. Data/
variable diproses dan ditransisikan dalam fung-
si.
• Misalnya String, bila ingin perubahan nilai, ob-
ject dihapus dan diganti, bukan di transisikan.
• Declarative style:
• Lebih fokus kepada apa yang ingin dicapai bu-
kan bagaimana mencapainya.
• Misalnya tidak menuliskan langkah-langkah ite-
rasi dalam memproses collection melainkan
menuliskan fungsi-fungi yang menyatakan apa
yang diinginkan dari collection tersebut.
• Lambdas:
• Fungsi tanpa nama, Sangat praktis dalam pen-
definisian dan manipulasi fungsi. (baca: lambda
calculus)

3
• Misalnya pembuatan anonymous inner class,
bisa digantikan dengan lambda.
• Streams:
• Infinite list, merepresentasikan data besar den-
gan elegan dan efisien
• Misalnya untuk pengolahan real time data tran-
saksi yang terus menerus dan sangat besar.
• Lazy evalution:

• Menunda evaluasi sampai benar-benar dibutuh-
kan.
• Misalnya dalam men—query data besar, dan • Processes
mengirimkan nya sebagai parameter, dapat te-
• An instance of running program that is isolated
tap dikirimkan secara keseluruhan tapi tidak
from other processes on the same machine
perlu memproses seluruhnya, dapat dibatasi
pada proses yang dibutuhkan saja (me-limit
komputasi). REST Webservice (Ch. 10)

Concurrency Concurrency REST (REpresentational State Transfer)


II (Ch. 9)

• Client Server
• Modular, backend dan frontend bisa dipisah
Ini materi OS. Gue jg gangerti
• Statelessness
• Shared Memory • Sifatnya stateless (simple, tidak usah men-track
client state)
• Shared objects di memori yang di akses oleh
concurrent modules yang berinteraksi satu sama • Cacheable
lain • If the client has access to a valid cached re-
• Concurrent modules interact by sending mes- sponse for a given request, it avoids repeating
sages to each other through a communication the same request. Instead, it uses its cached
channel copy
• Threads • Uniform Interface
• Unit terkecil dari sequence program yang di • REST API dari semua website mirip-mirip
manag oleh scheduler, yang merupakan bagian • Layered System
dari OS
• Di segregasi tergantung fungsionalitas, level au-
• Thread dan Runnable adalah dua cara membuat
throisasi yang dibutuhkan dll.
thread di Java
• Code on Demand
• Simplifies clients by reducing the number of
features required to be pre-implemented

You might also like