SlideShare uma empresa Scribd logo
1 de 40
OOP-對介面作設計programming to an interface, not an implementation ETREX 2011.04.18 http://etrex.blogspot.com/
什麼是介面?what
程式設計師認為的介面
程式設計師認為的介面
Google 圖片認為的介面
Google 圖片認為的介面
var USB插槽1: USB設備=newUSB滑鼠(); 我認為的介面是一種工業標準
var USB插槽1: USB設備=newUSB滑鼠(); 公的是介面實作者
var USB插槽1: USB設備=newUSB滑鼠(); 母的是介面使用者
public classPS2轉USB接頭 implementsPS2設備 { public varusb插槽:USB設備; } 雌雄同體!!!
public class延長線implements電器 { public var插槽1:電器; public var插槽2:電器; public var插槽3:電器; public var插槽4:電器; } 雌雌雌雌雄同體!!!
何時使用介面?when
程式碼重用的關鍵在於介面設計 reuse 一體成型 : 電視螢幕壞了 零組件化 : 電腦螢幕壞了 ?? 公
可以滿足未來需求嗎? 可抽換嗎?new requirement   電腦外接USB設備 Firefox外掛 母 母
如何設計一個好介面?how
介面的修改通常會造成大問題 O 向下相容:USB2.0 -> USB3.0 非向下相容 :AS2.0 -> AS3.0 Office2003 -> Office2007 改了就得重寫(學) X
良好的介面通常有多個實作 OS: 能不能多工 Interface: 能不能多公 JOKE XD
包裝未來需求 公 新需求交給新的Class 解決  不用修改舊程式碼 舊程式碼可重用 母 母
母 一體成型 的程式碼 -> 公 未來需求 重構refactoring
母 介面 公 未來需求 用介面包裝未來需求
母 以 不變 應 萬變 公 未來需求 超強 super strong
可是我不會包裝需求 怎麼辦?I can’t find the cut point
我覺得的步驟step 步驟1:先寫出一體成型的程式 步驟2:找出相同之處和不同之處 步驟3:把函數(程式碼)當變數
相同之處和不同之處 資料:相同的資料 不同的資料來源 UI:相同的資料 不同的顯示方式 應用程式:根據不同的狀態  滑鼠按下時有不同的行為
把函數(程式碼)當變數 var state : String = “init”; var state : 滑鼠行為= new Init滑鼠行為();
Function onMouseDown() {   If(state ==“init”)    {        //do init    }   else if(state == ….)    {   } } Function onMouseDown() { //超爽 state.onMouseDown(); }  差異在爽度
程式分層概念 分越多層 程式越慢 類別越多 程式碼越多
MySQL 傳資料 主程式 MSSQL 新需求 相同的資料 不同的資料來源
MySQL 主程式 MSSQL 統一存取資料的方法 新需求 相同的資料 不同的資料來源
表 傳資料 主程式 圖 新需求 相同的資料 不同的顯示方式
表 主程式 圖 統一顯示資料的方法 新需求 相同的資料 不同的顯示方式
設計模式design pattern
你已經學會的一些設計模式
public classPS2轉USB接頭 implementsPS2設備 { public varusb插槽:USB設備; } Adaptor Pattern
public class延長線implements電器 { public var插槽1:電器; public var插槽2:電器; public var插槽3:電器; public var插槽4:電器; } Composite Pattern
MySQL 主程式 MSSQL 統一存取資料的方法 新需求 Data Access Object(DAO)Pattern
把函數(程式碼)當變數 var state : String = “init”; var state : 滑鼠行為= new Init滑鼠行為(); Strategy Pattern
最近在寫的程式
ETREX大大講的我聽不懂 怎麼辦? Design Pattern是包裝需求的典範
謝謝大家Q & A

Mais conteúdo relacionado

Destaque

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Destaque (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Oop 對介面作設計