SOEN 387 Web-based Enterprise Application Design Stuart Thiel Fall, 2014
Transcription
SOEN 387 Web-based Enterprise Application Design Stuart Thiel Fall, 2014
1/23 SOEN 387 Web-based Enterprise Application Design Stuart Thiel SOEN 387 Web-based Enterprise Application Design Stuart Thiel Concordia University Department of Computer & Software Engineering Fall, 2014 Domain Model Outline Domain Model SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model 2/23 What are RDGs again? 3/23 I The hold raw data from DB records I The provide DB interaction behaviour SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model What is Domain Logic? I Behaviour associated with elements specific to the application I Elements that have meaning to the users of the application I Not specifically programatic classes SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model What If We Want Domain Logic? I What if we wanted to do something? I What if we wanted to qualify data? I What if we wanted to compare things? I Does .compareTo() or .equals belong in RDG? SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model Active Record I So, if we just add Domain Logic to RDGs, we get the Active Record pattern I Popular with Microsoft for a long time. . . maybe still It works, but low cohesion in those classes I I I I Domain Logic Raw Database Data DB interaction behaviour SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model POJO to the Rescue I So why not make a POJO that represents the record in memory I Keep it totally separate from the DB stuff I The it could hold Domain Logic and that would make sense SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model What About RDG Database Behaviour? 8/23 I We still need to interact with the DB I In exactly the same way. . . I But we don’t want to store the data in whatever does it SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model Table Data Gateway I A Table Data Gateway (TDG) fits the bill I Abstract Class with static methods to do everything I Takes raw data and adjusts DB I Takes DB and returns raw data (RecordSets) I Doesn’t know or care about these POJOs SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model How to Get to the POJO? 10/23 I So where do we get the POJO? I The TDG is at a lower level, POJO is clearly in Domain I We need something that can use the TDG as a service to decide which POJOs to make SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model Data Mapper I The Data Mapper fits this well! I It takes raw data/POJOs in finders and uses the TDG service to get ResultSets I It then converts the ResultSets into one or more POJO as needed I It takes the related POJOs and pulls out necessary raw data for insert/update/delete using the TDG service I One Mapper per type of POJO I Inheritance? Think about it, but we’ll do that later. SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model Diagram of POJO/TDG/DM 12/23 SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model I Splits off the database behaviour from everything else Fowler’s Joint TDG/Data Mapper I Fowler Merges the Data Mapper and TDG and calls it a Data Mapper I It spans two Layers. . . is that good? I Larman identifies that it’s easy and sensible to just split it into the two we use. SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model Diagram of Fowler’s DM 14/23 SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model I Does everything that Larman’s version does, just all in one class Making a Domain Model Diagram to Pick POJOs SOEN 387 Web-based Enterprise Application Design Stuart Thiel I How do we know which POJOs to use? I This is the most fundamental question in your webapp architecture I Talk with client, understand requirements I Make a Domain Model Diagram that makes sense to them Domain Model Checkers Example I Forget Players for now, let’s talk about the game I We conceptually have boards I We conceptually have pieces I Are Boards first-class objects? I Are Pieces first-class objects SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model What Behaviours for Checkerboards/Pieces? I What are the behaviours in a Checkers Game I I I I Pieces move Pieces eat other pieces Pieces upgrade to kings A Player wins SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model Where Does Checkerboard/Piece Behaviour Belong? 18/23 SOEN 387 Web-based Enterprise Application Design Stuart Thiel I So, should the board track winning? I Should the pieces track everything else? Domain Model Uber OO Design Diagram 19/23 SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model Conservative OO Design Diagram 20/23 SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model What Does Checkerboard Record Store? I Consider the more conservative design I A Checkerboard record stores the location of all pieces I 64 bits is enough to store all pieces of one type I There are four types of piece, king/normal for both sides I Can use fancy masks and store as 3 64bit bitstrings SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model What Does Checkerboard DM Do? I It reads the bitstrings and converts them into a more useable array for the Checkerboard POJO I Array is 8x8 and stores characters, ’r’, ’R’, ’b’, ’B’, null I Converts any newly updated 8x8 array back into these three bit masks SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model Checkerboard Behaviour I Decide if a move is valid I Decide if the move is a jump I Decide if a move results in a kinging I Make the move update 8x8 array SOEN 387 Web-based Enterprise Application Design Stuart Thiel Domain Model