Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ビジネスロジック実装進化論 - An Evolution of Business Logic ...

ビジネスロジック実装進化論 - An Evolution of Business Logic Implementation

DevLove 2010/10/27 発表資料。

Tadayoshi Sato

August 23, 2024
Tweet

More Decks by Tadayoshi Sato

Other Decks in Programming

Transcript

  1. • ࢓ࣄ - Software AGגࣜձࣾ άϩʔόϧίϯαϧλϯγʔ αʔϏε webMethodsίϯαϧλϯτ - ॻ੶ͷࣥචʗ຋༁ͳͲ

    • Web - ϒϩά: http://ameblo.jp/ouobpo - Twitter: tadayosi • झຯ - KindleͰಡॻ - ೔ຊϕδλϦΞϯڠձձһ ࠤ౻ ڡ߶ʢ͞ͱ͏ ͨͩΑ͠ʣ http://www.flickr.com/photos/robertnyman/189691155/
  2. #!/usr/bin/env perl use strict; use CGI::Carp qw(fatalsToBrowser); require ‘util.pl’ my

    %FORM = util::read_form('POST', 'utf8'); # ϏδωεϩδοΫʁ ... print "Content-type: text/html\n\n"; print<<HTML_END; <html> <head> <title>஫จ֬ೝ</title> </head> <body> ... </body> </html> HTML_END
  3. public class OrderServlet extends HttpServlet { protected void service( HttpServletRequest

    request, HttpServletResponse response) { processOrder(request, response); request .getRequestDispatcher( “/order/confirm.jsp”) .forward(request, response); } private void processOrder( HttpServletRequest request, HttpServletResponse response) { // ϏδωεϩδοΫʁ ... } ...
  4. υϝΠϯ૚ σʔλΞΫηε૚ ϓϨθϯ૚ Transaction Script DB ΞΫγϣϯ ΞΫγϣϯ ΞΫγϣϯ ΞΫγϣϯ

    αʔϏε ʢϢʔεέʔεAʣ αʔϏε ʢϢʔεέʔεBʣ αʔϏε ʢϢʔεέʔεCʣ αʔϏε ʢϢʔεέʔεDʣ DAO DAO DAO
  5. public class ProcessOrderServiceImpl implements IProcessOrderService { private IOrderDao fOrderDao; private

    ICustomerDao fCustomerDao; public List<OrderBean> findOrders( CustomerBean customer) { ... } public void confirmOrder( OrderBean order, CustomerBean customer) { ... } public void cancelOrder( OrderBean order, CustomerBean customer) { ... } ...
  6. Table Module υϝΠϯ૚ σʔλΞΫηε૚ ϓϨθϯ૚ DB ΞΫγϣϯ ΞΫγϣϯ ΞΫγϣϯ ΞΫγϣϯ

    αʔϏε ʢϢʔεέʔεAʣ αʔϏε ʢϢʔεέʔεBʣ αʔϏε ʢϢʔεέʔεCʣ αʔϏε ʢϢʔεέʔεDʣ DAO DAO DAO ϩδοΫ ʢςʔϒϧXʣ ϩδοΫ ʢςʔϒϧYʣ ϩδοΫ ʢςʔϒϧZʣ
  7. public class ProcessOrderServiceImpl implements IProcessOrderService { private IOrderLogic fOrderLogic; private

    ICustomerLogic fCustomerLogic; public List<OrderBean> findOrders( CustomerBean customer) { return fOrderLogic.findByCustomer(customer); } public void confirmOrder( OrderBean order, CustomerBean customer) { fOrderLogic.confirm(order, customer); } public void cancelOrder( OrderBean order, CustomerBean customer) { fOrderLogic.cancel(order, customer); } ...
  8. public class OrderLogicImpl implements IOrderLogic { private IOrderDao fOrderDao; private

    ICustomerLogic fCustomerLogic; public List<OrderBean> findByCustomer( CustomerBean customer) { return fOrderDao. findByCustomerId(customer.getId()); } public void confirm( OrderBean order, CustomerBean customer) { ... } public void cancel( OrderBean order, CustomerBean customer) { ... } ...
  9. Table Module • ϓϨθϯɺϏδωεϩδοΫɺσʔλΞΫη εͷ֤૚͸෼཭͞ΕΔ • ϏδωεϩδοΫ͸͞Βʹ2૚ʹ෼͔ΕΔ - Service Layer

    ʹ Ϣʔεέʔε୯Ґ - υϝΠϯϩδοΫ ʹ DBςʔϒϧ୯Ґ • ࣮༻ϨϕϧͰ͸໰୊ͳ͍͕ɺίʔυʹϜμ͕ ଟ͘ඒ͘͠ͳ͍
  10. ૯শؔ਺ʢCLOSʣ ;;; Ϋϥεఆٛ (defclass order () ((number :accessor order-number ...)))

    (defmethod confirm ((self order)) (... (order-number self))) ;;; ࣮ߦίʔυ (setq o (make-instance ‘order :number 12345)) (confirm o)
  11. ૯শؔ਺ → ΦϒδΣΫτ class OrderLogic { static void confirm( OrderBean

    order, CustomerBean customer) { order.getOrderNo(); ... OrderLogic .confirm(order, customer); class Order { String orderNo; void confirm( Customer customer) { this.orderNo; ... order.confirm(customer); Table Module Domain Model
  12. Domain Model υϝΠϯ૚ σʔλΞΫηε૚ ϓϨθϯ૚ DB ΞΫγϣϯ ΞΫγϣϯ ΞΫγϣϯ ΞΫγϣϯ

    αʔϏε ʢϢʔεέʔεAʣ αʔϏε ʢϢʔεέʔεBʣ αʔϏε ʢϢʔεέʔεCʣ αʔϏε ʢϢʔεέʔεDʣ ORM ORM ORM υϝΠϯ ΦϒδΣΫτ υϝΠϯ ΦϒδΣΫτ υϝΠϯ ΦϒδΣΫτ
  13. public class ProcessOrderServiceImpl implements IProcessOrderService { private IOrderRepository fOrderRepository; private

    ICustomerRepository fCustomerRepository; public List<Order> findOrders( Customer customer) { return fOrderRepository.findBy(customer); } public void confirmOrder(Order order) { order.confirm(); } public void cancelOrder(Order order) { order.cancel(); } ...
  14. public class Order { private Customer fCustomer; public void confirm()

    { ... } public void process() { ... } public void cancel() { ... } ...
  15. “Architecture teams must not siphon off all the best and

    brightest.” ΞʔΩςΫνϟνʔϜʹ ࠷΋༏लͳϝϯό ΛूΊͯ͸͍͚ͳ͍ɻ — Eric Evans, Domain-Driven Design