Twitter - Quiz Tutors
Dependency Injection Pattern - Computer Science. Facebook - Quiz Tutors

Substitution Principle, Dependency Injection Pattern, Open/Close Principle

The key terms of this chapter include Substitution Principle, Dependency Injection Pattern, Open/Close Principle, Java.


Dependency Injection Pattern

Instantiate object outside class –> inject it into the class (pass into constructor)
In Model class, passes Database object into class
Benefit: looser coupling, enable separation of concerns (class does not need to know how to instantiate object)
Object being injected = SERVICE
code passing in service = INJECTOR


MVC Pattern

For web applications
higher level
Model <–> Controller <–> View


Gang Of Four – Design Patterns

Creational Patterns – how to create objects
Structural Patterns – how to organize classes/objects
Behavioral Patterns – how classes interact with each other


Composite

structural design pattern – compose objects —> tree structures to represent whole-part hierarchies
Grouping & ungrouping primitive types
– treat a group of objects same way as single instance
Enables nesting


Adaptor

structural design pattern – allows interface of existing class to be used as another interface & allows objects w/ incompatible interfaces to collaborate
adaptor is a
Uses dependency Inversion Principle
– adaptor implements an interface that Client calls on


Factory

creational design pattern – replace direct object construction calls (new) with a factory method
Establishing constructor
DriverManager.getConnection(URI)
Not coupled to client


SQL

language to speak to DBMS


Singleton

creational design patter – ensure class has only one instance & providing global access point to instance
Don’t want several instances to access same info
Use static final
Java application – Runtime class – single instance
– use getRuntime to get the one instance of Runtime


Iterator

behavioral design pattern – traverse elements of a collection w/out exposing underlying representation
Open/close principle
– when creating new iterator — build on existing iterator


Rainbow attack

A precomputed table for reversing cryptographic hash functions (usually password hashes).


Solution to hash attacks

add salt – random string as additional input to one-way hashing function


MD5

a type of hashing function
not good anymore – only good for slow functions


Bcrypt

safest hashing function
can add this to gradle


What is a good principle when writing tests

unit tests should not depend on other tests


relational databases

store info in tables that are related to each other


DBMS

Database management system, a software suite designed to organize and search data.


Table

Rows: values (data)
Columns: attributes


SQL

language to speak to DBMS


JDBC API

Java Database Connectivity
JAVA –JDBC–> DBMS
Connection conn = DriverManager.getConnection(URI)


SOLID Design Principles

Single responsibility, Open/close, Liskov substitution, Interface segregation, Dependency inversion


Single responsibility Principle

A class, method, variable should only have one responsibility (purpose)


Open/Close Principle

not changing existing code but can extend functionality


Liskov Substitution Principle

Subclasses should be substitutable for their base classes
assess whether is using inheritance correctly


Homepage