Download presentation
Presentation is loading. Please wait.
Published byFrederick Day Modified over 8 years ago
2
T YPES OF M ODELS Prasun Dewan Department of Computer Science University of North Carolina at Chapel Hill dewan@cs.unc.edu Code available at: https://github.com/pdewan/ColabTeachinghttps://github.com/pdewan/ColabTeaching
3
2 P RE -R EQUISITES Model-Interactor Separation
4
3 M ODEL T YPES Model Interactor Types of models?
5
4 G ENERAL P ATTERN Model Interactor Write methods Read methods
6
5 E XAMPLE ASimpleList Interactor add() size() get() Write methods Read methods
7
6 L IST M ODELS List Model Interactor add() Write methods Read methods size() get() delete() Models define methods to read and write indexed elements in variable length lists They differ in the set of write methods
8
7 L OGICAL VS. P HYSICAL S TRUCTURE public class ASimpleList implements SimpleList { List simpleList = new ArrayList(); List > observers = new ArrayList(); public void add(ElementType anElement) { simpleList.add(simpleList.size(), anElement); } public void observableAdd(int anIndex, ElementType anElement) { add(anIndex, anElement); notifyAdd(anIndex, anElement); } public void notifyAdd(List > observers, int index, ElementType newValue) { for (ListObserver observer:observers) observer.elementAdded(index, newValue); } … } Replacing array list with array does not change logical structure of model, which is determined by public methods ArrayList Array?
9
8 O THER M ODELS ? List Model Interactor add() Write methods Read methods size() get() delete() Models define methods to read and write indexed elements in variable length lists They differ in the set of write methods Other important kinds of models?
10
9 B EAN M ODELS Bean Model Interactor setP1() Write methods Read methods getP1() getP2() setP2() Models define getter and setter methods to read fixed number of typed properties
11
10 R EAD - ONLY AND E DITABLE P ROPERTIES public class C { } public T getP() {... } public void setP(T newValue) {... } Typed, Named Unit of Exported Object State Name P Type T Name P Type T Read-only Editable Getter method Setter method newP obtainP Violates Bean convention Bean Bean convention: For humans and tools
12
11 I NDEXED B EAN Bean also defines fixed length indexed collections which we will ignore
13
12 M ODEL C OMPOSITION Bean Model List Model Bean Model
14
13 C OMPOSING H ISTORY M ODEL We already have a model for History
15
14 E XAMPLE M ODEL C OMPOSITION IM Bean Model Simple List History Topic
16
15 C ONNECTING M ODEL /I NTERACTOR H IERARCHIES Model Bean Model Interactor A model subtree can be connected to a single interactor A model can be connected to an interactor subtree
17
16 S UMMARY OF M ODELS Lists Variable length indexed lists Differ based on subsets of list operations exposed Beans Property collections Differ in properties Table model is another important kind not needed in this course Model composition Useful when user interfaces are composed Model hierarchies can be connected to interactor hierarchies in arbitrary ways
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.