Presentation is loading. Please wait.

Presentation is loading. Please wait.

ANU COMP2110 Software Design in 2004 Lecture 17Slide 1 COMP2110 in 2004 Software Design Lecture 17: Software design patterns (4) 1The Abstract Factory.

Similar presentations


Presentation on theme: "ANU COMP2110 Software Design in 2004 Lecture 17Slide 1 COMP2110 in 2004 Software Design Lecture 17: Software design patterns (4) 1The Abstract Factory."— Presentation transcript:

1 ANU COMP2110 Software Design in 2004 Lecture 17Slide 1 COMP2110 in 2004 Software Design Lecture 17: Software design patterns (4) 1The Abstract Factory pattern 2Adapter pattern

2 ANU COMP2110 Software Design in 2004 Lecture 17Slide 2 Abstract Factory (1) Abstract Factory is a creational pattern – like these abstract factory factory singleton prototype other types: structural façade, composite, adapter,... behavioral observer, iterator, command, state, visitor,...

3 ANU COMP2110 Software Design in 2004 Lecture 17Slide 3 Creational patterns Creational patterns are ways of organising the creation of many objects (beyond new, creation, constructor) Factorycreate new objects when the constructor alone is not enough Singletoncreate only one widely shared object with a public accessor method Prototypecreate sets of objects like example objects Abstract Factorycreate families of objects in related groups

4 ANU COMP2110 Software Design in 2004 Lecture 17Slide 4 Abstract Fcatory - an example [2001 exam] A software system for handling student results has these requirements: 1.There are two classes of students: Arts and Science. Each Faculty will have its own set of records, one for all Arts students, the other for all Science students. 2.A student's record contains an ID number, type of degree, and marks for all subjects taken this semester. 3.Arts students’ records have their major discipline (a string like "History"). 4.Arts students only take Arts subjects; Science students only take Science subjects. 5.Each arts student takes 4 subjects, each science student takes only 3. 6.Every subject has a name and a subject code. 7.Arts subjects have an exam mark and an essay mark, each out of 100. 8.Science subjects have an exam mark out of 100 and two assignment marks 9.Every subject has a final mark that can be computed by a function called final. 10.The same method called grade is used for all subjects for calculating the grade from the final mark.

5 ANU COMP2110 Software Design in 2004 Lecture 17Slide 5 Students and subjects ArtsStudt major SciStudt exam essay final() exam asg1 asg2 final() ArtsSubjtScienceSubj t Student ID,degree Subject ScienceRecordMaker CreateStudent() CreateSubject() > ArtsRecordMaker CreateStudent() CreateSubject() AbstractRecordMaker CreateStudent() CreateSubject() RM = new ArtsRecordMaker() // or new ScienceRecordMaker() s = RM.CreateStudent() -- includes setNSubjs for sc in [1..s.NSubjs] s.subject[sc]= RM.CreateSubject()

6 ANU COMP2110 Software Design in 2004 Lecture 17Slide 6 Abstract Factory – the Pattern (GoF p87+) Intent: provide an interface for creating families of related or dependent objects without specifying their concrete classes Applicability: use when a system should be independent of how its products are created, composed, represented a system should be configured with one or more multiple families of products a family of related products is designed to be used together, and you need to enforce this constraint you want to provide a class library of products, and you want to reveal their interfaces, not their implementations

7 ANU COMP2110 Software Design in 2004 Lecture 17Slide 7 Abstract Factory – the general structure see diagram – Jezequel p. 87

8 ANU COMP2110 Software Design in 2004 Lecture 17Slide 8 Abstract Factory – the Pattern (GoF p87+) Consequences: isolates concrete classes makes exchanging product families easy (e.g. add a new Faculty – just another ConcreteFactory class like ArtsRecordMaker) promotes consistency among products BUT – supporting new families of products is difficult because the interface fixes the set of products in the family (e.g. [CreateStudent, CreateSubject])

9 ANU COMP2110 Software Design in 2004 Lecture 17Slide 9 ArtsStudt major SciStudt exam essay final() exam asg1 asg2 final() ArtsSubjtScienceSubj t Student ID,degree Subject ScienceRecordMaker CreateStudent() CreateSubject() ArtsRecordMaker CreateStudent() CreateSubject() AbstractRecordMaker CreateStudent() CreateSubject() Abstract Factory ConcreteFactory1 ConcreteFactory2 Abstract ProductA Abstract ProductB ProductA1 ProductA2 ProductB2 ProductB1

10 ANU COMP2110 Software Design in 2004 Lecture 17Slide 10 lecture continues... more on Abstract Factory – see separate HTML notes 17.2 abstract-factory.html Adapter – see separate HTML notes 17.3 adapter.html


Download ppt "ANU COMP2110 Software Design in 2004 Lecture 17Slide 1 COMP2110 in 2004 Software Design Lecture 17: Software design patterns (4) 1The Abstract Factory."

Similar presentations


Ads by Google