1 / 21

單元 4 :數位家庭軟體開發與再利用 Chapter 4-3 – Mapping Models to Code

單元 4 :數位家庭軟體開發與再利用 Chapter 4-3 – Mapping Models to Code. Software lift cycle. Software life cycle. Development cycle. Requirements Engineering. Design. Implementation. Testing. Requirements Elicitation. System design. Mapping. Analysis. Object design. SRS. Analysis Model

Télécharger la présentation

單元 4 :數位家庭軟體開發與再利用 Chapter 4-3 – Mapping Models to Code

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 單元4:數位家庭軟體開發與再利用Chapter 4-3 – Mapping Models to Code

  2. Software lift cycle Software life cycle Development cycle Requirements Engineering Design Implementation Testing Requirements Elicitation System design Mapping Analysis Object design SRS Analysis Model (Class diagrams) ODD (Class diagram) ODD (Class diagram) Code Source code Maintenance

  3. Mapping Activities • Mapping Object Design model (Doc.) (Class diagram) 1.Mapping Associations (concept) Unidirectional, one-to-many association Bidirectional, one-to-many association Aggregation 2.Mapping Contracts to Exceptions Source Code 3.Mapping Object Models to a Persistent Storage Schema RDB Table

  4. Class Diagram 使用者 1 1 * 上傳 學生 老師 * 作業資料 修課 課程 個人作業

  5. Mapping Object Models to RDB 課程 編號 老師帳號 名稱 學期 說明 作業資料 修課 個人作業 帳號 Office Hour 辦公室 課程編號 組別 學生帳號 使用者 老師 學生 帳號 帳號 系別 密碼 編號 功課編號 電子郵件 課程編號 學生帳號 名稱 電話 檔名 截止日期 大小 作業或報告

  6. What is mapping? • A transformation aims at improving one aspect of the model (e.g., its modularity) while preserving all of its other properties (e.g., its functionality). (model在改善某一方面所做的轉變,同時維持其功能的特性) • A transformation is usually localized, affects a small number of classes, attributes, and operations, and is executed in a series of small steps. (這些轉變是經過一些連續的步驟,是局部的、影響少數的class, attributes, operation)

  7. Four types of transformations Object Model space Source code space Forward engineering (CH 4-3) Modeltransformation (CH 3-6) Refactoring (CH 4-3) Reverse engineering

  8. Model Transformation Example Object design model before transformation: 學生 老師 使用者 +Id:String +Password:String +Id:String +Password:String +Id:String +Password:String Object design model after transformation: 學生 老師 +OfficeHour:String

  9. Reuse concepts • The focus of inheritance during object design is to “reduce redundancy” and “enhance extensibility”. (目的為降低系統重覆提高延展性) • Steps of design inheritance: • Step1: to factor all redundant behavior into a single superclass. (步驟一:把重複的屬性操作都放到一個superclass) • Step2: we reduce the risk of introducing inconsistencies during changes since we have to make changes only once for all subclass. (步驟二:為了降低不一致的狀況發生,同時間我們只做一次步驟一的行為,換句話說,就是一次只產生一個superclass)

  10. Refactoring Example: Pull Up Field • Before Refactoring public class Student{ private String Id; private String Password; //... } public class Teacher{ private String Id; private String Password; //... } • After Refactoring public class User { private String Id; private String Password; } public class Student : User { //... } public class Teacher : User { //... }

  11. Forward Engineering Example Realization of User and Teacher public class User { public String Id; public String Password; } public class Teacher:User { public string OfficeHour; public string Room; } 老師 Object design model before transformation 使用者 +OfficeHour:String +Room: String +Id:String +Password:String Source code after transformation

  12. Transformation Principles • To avoid introducing new errors, all transformations should follow these principles: • Each transformation must address a single criteria. (每個Transformation是滿足一單一標準,是增進系統在單一目的,如一個transformation是為了簡化類別) • Each transformation must be local. (Transformation是只有少數的method or class) • Each transformation must be applied in isolation to other changes. (Transformation與其他的改變是隔離) • Each transformation must be followed by a validation step. (Transformation是人工的,應該要有確認的步驟以維持功能需求)

  13. Unidirectional one-to-many association Object design model before transformation public class HomeworkData{ private TakeCourse _tc; private File _file; public Student getStudent() { return _tc.getStudent(); } public File getFile(){ return _file; } public HomeworkData(TakeCourse tc){ _tc = tc; } //… } public class TakeCourse{ private Course _course; private Student _student; public TakeCourse(){ } public Student getStudent(){ return _student; } //… } * 上傳 1 Source code after transformation 作業資料 修課

  14. Bidirectional one-to-many association Object design model before transformation public class Student : User{ privateCollection<TakeCourse> _takeCourses; public Collection<TakeCourse> getTakeCourses() { return _takeCourses; } } public class TakeCourse{ private Student _student; private Course _course; public Student getStudent(){ return _student; } public void setStudent(Student student){ _student = student; } public Course getCourse(){ return _course; } } 修課 學生 Source code after transformation 修課 1 *

  15. Aggregation Object design model before transformation public class Teacher: User { private Collection <Courses > _courses; public List getCourses(){ return _courses; } } public class Course { private Teacher _teacher; public Teacher getTeacher(){ return _teacher; } public void setTeacher(Teacher teacher){ _teacher = teacher; } } Source code after transformation 老師 課程

  16. Class diagram contracts with OCL HomeworkData Public class HomeworkData { context HomeworkData::setFile(file:File) pre: file.size <= 3145728 andfile.size > 0 and !file.FileName.EndWith.include(‘.bat’, ‘.exe’) context HomeworkData::setFile(file:File) post: self._uploadDate = DateTime.Now self._file = file } -_student : Student -_file : File -_uploadDate: DateTime +setFile(file: File ) : void +getFile() : File +getStudent():Student +setStudent(student: Student ) : void +getUploadDate() : DateTime +setUploadDate() : void

  17. Mapping Contracts to Exceptions Public class HomeworkData{ //… Public void setFile(File file){ if(file.size() > 3145728 || file.size () <= 0) throw new OutofRangeException(“..”) ; if( file.size () <= 0) throw new OutofRangeException(“..”) ; const string[] filter = new string[]{“.bat”,”.exe”}; foreach(string s in filter){ if( file.FileName.EndWith(s) ) throw new SecurityException(“..”) } //… _uploadData = DateTime.Now; _file = file; } //.. }

  18. Mapping Object Models to a Persistent Storage Schema • UML object models mapping to relational databases: • UML mappings • Each class is mapped to a table(每個類別映射到一個資料表) • Each class attribute is mapped onto a column in the table(每個屬性對應到資料表的一個欄位) • An instance of a class represents a row in the table(資料表中的每個資料錄是對映到class的instance) • Inheritance association • Aone-to-many association is implemented as buried foreign key(一對多的關連是用外來鍵實做)

  19. Primary key Foreign key referencing Foreign key referencing Inheritance Association 學生 老師 帳號 CHAR(20) 帳號 CHAR(20) 帳號 CHAR(20) 系別 CHAR(20) 密碼 CHAR(20) Office Hour CHAR(20) 電子郵件 CHAR(50) 辦公室 CHAR(50) … 電話 CHAR(20) 使用者 使用者 學生 老師

  20. Primary key Mapping Object 學生 課程 帳號 CHAR(20) 編號 BIGINT 學生帳號 CHAR(20) 課名 CHAR(20) 系別 CHAR(20) 課程編號 BIGINT … … 組別 INT 修課 1 * 學生 修課 課程

  21. Primary key Mapping Object 作業資料 學生帳號 CHAR(20) 編號 BIGINT 課程編號 BIGINT 學生帳號 BINARY 作業項目編號 BIGINT 組別 INT 檔名 CHAR(255) 大小 BIGINT 檔案 BINARY 修課 * 上傳 1 作業資料 修課

More Related