SlideShare a Scribd company logo
1 of 11
Design Pattern ,[object Object]
Builder PatternM5440047 นายวสุพล เผือกนำผล
Abstraction Occurrence Solution:
One-to-Many * Manager Account ตัวอย่าง: ผู้จัดการหนึ่งคน ถือบัญชีได้หลายบัญชี 1 คำแนะนำ: วิธีง่ายที่สุดในการเขียนคำสั่ง ประเภท one-to-many คือใช้คลาส ใน library ของภาษาที่มีมาให้ เช่น ในจาวา ได้แก่ List, Vector, หรืออาจเขียนเป็นอะเรย์เองก็ได้ แต่ยุ่งยาก ในการจัดการ public class Manager  {    public void addAccount(Account acc) { theAccounts.addElement(acc);     }      public void removeAccount(Account acc)  {  theAccounts.removeElement(acc); 	} private VectortheAccounts; }
* Student StudentGrade 1 public class Student {    private List<StudentGrade> grades;}public class StudentGrade {    private char letterGrade;    private double percentageGrade;}
การใช้ hasMany ตัวอย่าง ผู้แต่งหนังสือ สามารถแต่หนังหรือได้มากกว่า 1 เล่ม ( one-to-many )  hasManyในการกำหนดความสัมพันธ์แบบ one-to-many class Author {   static hasMany = [books:Book]} java.util.SortedSet class Author {   SortedSet books   static hasMany = [books:Book]} ชนิดของตัวแปรที่กำหนดให้สัมพันธ์กันนั้น จะมี default เป็น java.util.Set
 Lists of objects  เก็บ array ไม่จำกัดขนาด และสามารถอ้างถึงข้อมูลด้วย index  ใช้งานผ่าน java.util.List class Author {   List books   static hasMany = [books:Book]} การอ้างถึงข้อมูล author.books[0] // get the first book
Builder Pattern

More Related Content

Viewers also liked

สถาปัตยกรรมเครือข่ายคอมพิวเตอร์
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์สถาปัตยกรรมเครือข่ายคอมพิวเตอร์
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์driftmaric
 
Sagrada familia windows
Sagrada familia windowsSagrada familia windows
Sagrada familia windowsRebecca Jardin
 
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์สถาปัตยกรรมเครือข่ายคอมพิวเตอร์
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์driftmaric
 
Grade 7 Poetry Painting
Grade 7 Poetry PaintingGrade 7 Poetry Painting
Grade 7 Poetry PaintingRebecca Jardin
 
Surreal Handscapes 9 and 10
Surreal Handscapes 9 and 10Surreal Handscapes 9 and 10
Surreal Handscapes 9 and 10Rebecca Jardin
 
Software testing
Software testingSoftware testing
Software testingDIPEN SAINI
 
Domain specific Software Architecture
Domain specific Software Architecture Domain specific Software Architecture
Domain specific Software Architecture DIPEN SAINI
 

Viewers also liked (11)

สถาปัตยกรรมเครือข่ายคอมพิวเตอร์
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์สถาปัตยกรรมเครือข่ายคอมพิวเตอร์
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์
 
4.22
4.224.22
4.22
 
Magic square
Magic squareMagic square
Magic square
 
Sagrada familia windows
Sagrada familia windowsSagrada familia windows
Sagrada familia windows
 
Assessment 1
Assessment 1Assessment 1
Assessment 1
 
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์สถาปัตยกรรมเครือข่ายคอมพิวเตอร์
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์
 
Grade 7 photography
Grade 7 photographyGrade 7 photography
Grade 7 photography
 
Grade 7 Poetry Painting
Grade 7 Poetry PaintingGrade 7 Poetry Painting
Grade 7 Poetry Painting
 
Surreal Handscapes 9 and 10
Surreal Handscapes 9 and 10Surreal Handscapes 9 and 10
Surreal Handscapes 9 and 10
 
Software testing
Software testingSoftware testing
Software testing
 
Domain specific Software Architecture
Domain specific Software Architecture Domain specific Software Architecture
Domain specific Software Architecture
 

Desing pattern

  • 1.
  • 4. One-to-Many * Manager Account ตัวอย่าง: ผู้จัดการหนึ่งคน ถือบัญชีได้หลายบัญชี 1 คำแนะนำ: วิธีง่ายที่สุดในการเขียนคำสั่ง ประเภท one-to-many คือใช้คลาส ใน library ของภาษาที่มีมาให้ เช่น ในจาวา ได้แก่ List, Vector, หรืออาจเขียนเป็นอะเรย์เองก็ได้ แต่ยุ่งยาก ในการจัดการ public class Manager { public void addAccount(Account acc) { theAccounts.addElement(acc); } public void removeAccount(Account acc) { theAccounts.removeElement(acc); } private VectortheAccounts; }
  • 5.
  • 6. * Student StudentGrade 1 public class Student {    private List<StudentGrade> grades;}public class StudentGrade {    private char letterGrade;    private double percentageGrade;}
  • 7.
  • 8. การใช้ hasMany ตัวอย่าง ผู้แต่งหนังสือ สามารถแต่หนังหรือได้มากกว่า 1 เล่ม ( one-to-many ) hasManyในการกำหนดความสัมพันธ์แบบ one-to-many class Author {   static hasMany = [books:Book]} java.util.SortedSet class Author {   SortedSet books   static hasMany = [books:Book]} ชนิดของตัวแปรที่กำหนดให้สัมพันธ์กันนั้น จะมี default เป็น java.util.Set
  • 9.  Lists of objects เก็บ array ไม่จำกัดขนาด และสามารถอ้างถึงข้อมูลด้วย index  ใช้งานผ่าน java.util.List class Author {   List books   static hasMany = [books:Book]} การอ้างถึงข้อมูล author.books[0] // get the first book
  • 10.
  • 12. reference https://sites.google.com/site/thaigrails/gorm/domain-modelling-in-gorm/sets--lists-and-maps http://resource.visual-paradigm.com/java_orm/using_model_api_with_java_persistence_class.html http://stackoverflow.com/questions/2252377/properly-implementing-a-one-to-many-unidirectional-relationship-in-hibernate http://www.narisa.com/blog/up1/index.php?showentry=1812 http://th.wikipedia.org/wiki/Abstract_factory_pattern http://www.oodesign.com/ http://kunchorn.wordpress.com/2009/06/15/หัวข้อที่สอง-builder-pattern/ http://www.narisa.com/forums/index.php?showtopic=3455 d