Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Homeworks/Answer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
1. Homework1
Bridge pattern: folder bridge
Shape có 2 loại thể hiện là: Triangle, Circle
Color có 2 loại thể hiện là: GreenColor, BlueColor
Theo bridge pattern:
- Abstraction: Circle, Triangle
- Implementation: GreenColor, Bluecolor
Absraction sẽ sử dụng 1 trong các Implementation để tô màu cho Shape

Null Object Pattern: folder null_obejct_pattern
Nếu không có subscription -> Return Nosubscription.new

Factory Method: folder factory_method
- Creator: Shape
- Creator implementation: Circle, Rectangle, Square
- Factory: ShapeFactory
Khi muốn khởi tạo Circle, Rectangle, Square chỉ cần khởi tạo qua ShapeFactory
VD: new Shape("CIRCLE")
-> "creating objects without having to specify the exact class of the object that will be created"
4 changes: 4 additions & 0 deletions Homeworks/bridge/BlueColor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public class BlueColor implements Color{
public void fillColor(){
}
}
4 changes: 4 additions & 0 deletions Homeworks/bridge/Circle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public class Circle extends Shape{
public void get() {
}
}
3 changes: 3 additions & 0 deletions Homeworks/bridge/Color.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface Color {
public void fillColor();
}
5 changes: 5 additions & 0 deletions Homeworks/bridge/GreenColor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class GreenColor implements Color{
public void fillColor(){

}
}
13 changes: 13 additions & 0 deletions Homeworks/bridge/Shape.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class Shape {
private Object implementation;

public Shape(Object implementation) {
this.implementation = implementation;
}

public void paint() {
}

public void getColor() {
}
}
4 changes: 4 additions & 0 deletions Homeworks/bridge/Triangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public class Triangle extends Shape{
public void get() {
}
}
Binary file added Homeworks/bridge/bridge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions Homeworks/bridge/bridge.uml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>JAVA</ID>
<OriginalElement />
<nodes>
<node x="150.0" y="462.0">jdk</node>
<node x="146.0" y="169.0">Circle</node>
<node x="338.125" y="456.25">java</node>
<node x="34.0" y="0.0">Shape</node>
<node x="175.0" y="366.0">BlueColor</node>
<node x="87.5" y="265.0">Color</node>
<node x="0.0" y="169.0">Triangle</node>
<node x="0.0" y="462.0">sun</node>
<node x="0.0" y="366.0">GreenColor</node>
</nodes>
<notes />
<edges>
<edge source="Circle" target="Shape">
<point x="0.0" y="-25.5" />
<point x="209.0" y="144.0" />
<point x="187.0" y="144.0" />
<point x="51.0" y="59.5" />
</edge>
<edge source="Triangle" target="Shape">
<point x="0.0" y="-25.5" />
<point x="63.0" y="144.0" />
<point x="85.0" y="144.0" />
<point x="-51.0" y="59.5" />
</edge>
<edge source="GreenColor" target="Color">
<point x="0.0" y="-25.5" />
<point x="77.5" y="341.0" />
<point x="126.25" y="341.0" />
<point x="-38.75" y="25.5" />
</edge>
<edge source="BlueColor" target="Color">
<point x="0.0" y="-25.5" />
<point x="252.5" y="341.0" />
<point x="203.75" y="341.0" />
<point x="38.75" y="25.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.6" x="277.5" y="223.5625" />
<SelectedNodes />
<Categories>
<Category>Methods</Category>
<Category>Constructors</Category>
<Category>Properties</Category>
<Category>Fields</Category>
</Categories>
<SCOPE>All</SCOPE>
<VISIBILITY>private</VISIBILITY>
</Diagram>

5 changes: 5 additions & 0 deletions Homeworks/factory_method/Circle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Circle implements Shape {
public void draw() {
System.out.println("Circle");
}
}
5 changes: 5 additions & 0 deletions Homeworks/factory_method/Rectangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Rectangle implements Shape {
public void draw() {
System.out.println("Shape");
}
}
3 changes: 3 additions & 0 deletions Homeworks/factory_method/Shape.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface Shape {
void draw();
}
18 changes: 18 additions & 0 deletions Homeworks/factory_method/ShapeFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class ShapeFactory {
public Shape getShape(String shapeType){
if(shapeType == null){
return null;
}
if(shapeType.equalsIgnoreCase("CIRCLE")){
return new Circle();

} else if(shapeType.equalsIgnoreCase("RECTANGLE")){
return new Rectangle();

} else if(shapeType.equalsIgnoreCase("SQUARE")){
return new Square();
}

return null;
}
}
5 changes: 5 additions & 0 deletions Homeworks/factory_method/Square.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Square implements Shape {
public void draw() {
System.out.println("Square");
}
}
Binary file added Homeworks/factory_method/factory_method.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions Homeworks/factory_method/factory_method.uml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>JAVA</ID>
<OriginalElement />
<nodes>
<node x="252.0" y="197.0">META-INF</node>
<node x="161.0" y="293.0">com</node>
<node x="150.0" y="441.0">jdk</node>
<node x="0.0" y="101.0">Circle</node>
<node x="156.0" y="0.0">Shape</node>
<node x="0.0" y="367.0">java</node>
<node x="154.0" y="367.0">org</node>
<node x="0.0" y="293.0">javax</node>
<node x="156.0" y="101.0">Rectangle</node>
<node x="0.0" y="197.0">ShapeFactory</node>
<node x="312.0" y="101.0">Square</node>
<node x="0.0" y="441.0">sun</node>
</nodes>
<notes />
<edges>
<edge source="Circle" target="Shape">
<point x="0.0" y="-25.5" />
<point x="68.0" y="76.0" />
<point x="178.66666666666666" y="76.0" />
<point x="-45.33333333333334" y="25.5" />
</edge>
<edge source="Rectangle" target="Shape">
<point x="0.0" y="-25.5" />
<point x="0.0" y="25.5" />
</edge>
<edge source="Square" target="Shape">
<point x="0.0" y="-25.5" />
<point x="380.0" y="76.0" />
<point x="269.33333333333337" y="76.0" />
<point x="45.33333333333337" y="25.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="224.0" y="224.0" />
<SelectedNodes>
<node>META-INF</node>
</SelectedNodes>
<Categories>
<Category>Fields</Category>
<Category>Constructors</Category>
<Category>Methods</Category>
<Category>Properties</Category>
<Category>Inner Classes</Category>
</Categories>
<SCOPE>All</SCOPE>
<VISIBILITY>public</VISIBILITY>
</Diagram>

13 changes: 13 additions & 0 deletions Homeworks/null_object_pattern/no_subscription.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class NoSubscription
def charge(credit_card)
"No Charge"
end

def price
0
end

def has_mentoring?
false
end
end
Binary file added Homeworks/null_object_pattern/null_object.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions Homeworks/null_object_pattern/null_object.uml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>JAVA</ID>
<OriginalElement />
<nodes>
<node x="127.0" y="2.0">User</node>
<node x="123.0" y="247.0">NoSubscription</node>
</nodes>
<notes />
<edges />
<settings layout="Hierarchic Group" zoom="1.0" x="745.0" y="407.5" />
<SelectedNodes>
<node>NoSubscription</node>
</SelectedNodes>
<Categories>
<Category>Inner Classes</Category>
<Category>Properties</Category>
<Category>Methods</Category>
<Category>Fields</Category>
<Category>Constructors</Category>
</Categories>
<SCOPE>All</SCOPE>
<VISIBILITY>public</VISIBILITY>
</Diagram>

19 changes: 19 additions & 0 deletions Homeworks/null_object_pattern/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class User
attr_accessor :credit_card, :subscription

def charge
subscription.charge credit_card
end

def has_mentoring?
subscription.has_mentoring?
end

def price
subscription.price
end

def subscription
@subscription ||= NoSubscription.new
end
end