16
TYPES OF MODELS Prasun Dewan Department of Computer Science University of North Carolina at Chapel Hill [email protected] Code available at: https:// github.com/pdewan/ColabTeaching

Types of Models

Embed Size (px)

DESCRIPTION

Types of Models. Prasun Dewan Department of Computer Science University of North Carolina at Chapel Hill [email protected] Code available at: https:// github.com/pdewan/ColabTeaching. Pre-Requisites. Model- Interactor Separation. Model Types. Interactor. Model. Types of models?. - PowerPoint PPT Presentation

Citation preview

Slide 1

Types of ModelsPrasun DewanDepartment of Computer ScienceUniversity of North Carolina at Chapel [email protected] available at: https://github.com/pdewan/ColabTeaching

#Pre-RequisitesModel-Interactor Separation

#Model TypesModelInteractorTypes of models?

#General PatternModelInteractorWrite methodsRead methods

#ExampleASimpleListInteractoradd()size()get()Write methodsRead methods

#List ModelsList ModelInteractoradd()Write methodsRead methodssize()get()delete()Models define methods to read and write indexed elements in variable length listsThey differ in the set of write methods

#Logical vs. Physical Structurepublic 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 methodsArrayListArray?

#Other Models?List ModelInteractoradd()Write methodsRead methodssize()get()delete()Models define methods to read and write indexed elements in variable length listsThey differ in the set of write methodsOther important kinds of models?

#Bean ModelsBean ModelInteractorsetP1()Write methodsRead methodsgetP1()getP2()setP2()Models define getter and setter methods to read fixed number of typed properties

#Read-only and Editable Propertiespublic class C{}public T getP() { ...}public void setP(T newValue) { ...}Typed, Named Unit of Exported Object StateName P

Type TRead-onlyEditableGetter methodSetter methodnewPobtainPViolates Bean conventionBeanBean convention:For humans and tools

#Indexed BeanBean also defines fixed length indexed collections which we will ignore

#Model CompositionBean ModelList ModelBean ModelBean Model

#

Composing History ModelWe already have a model for History

#Example Model CompositionIM Bean ModelSimple List

Simple ListHistoryTopic#Connecting Model/Interactor HierarchiesModelModelModelBean ModelInteractorInteractorInteractorA model subtree can be connected to a single interactorA model can be connected to an interactor subtree

#Summary of ModelsLists Variable length indexed listsDiffer based on subsets of list operations exposedBeans Property collectionsDiffer in propertiesTable model is another important kind not needed in this courseModel compositionUseful when user interfaces are composedModel hierarchies can be connected to interactor hierarchies in arbitrary ways

#