Professional Documents
Culture Documents
classes.
• When there are interrelated dependencies with
not-that-simple creation logic involved
• Builder
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)
• 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.
• 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
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)
• 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