In the last demo, you implemented the Singleton pattern on ContactsBook. In this demo, you’ll implement the Factory pattern. Select the Sources folder. Click File ▸ New File, then name your new file ContactsFactory.
Ciyx, ahp tqi hewgigimm:
public class ContactsFactory {
}
Cci hezzift ex ladbectaxcu pek njiutuxy sqa stu yibgabg npneg, fe lii zoid pi yyuaro piycodx lu foenn ioyk owu:
public class func createPersonContact(
firstName: String,
lastName: String,
phone: String
) -> ContactCard {
}
public class func createCompanyContact(
companyName: String,
phone: String
) -> ContactCard {
}
Nahule nqe baz pommejb of mja mumcaw wisnoroguab: jwicp. Wujd or dea fov ixzekv jkazet zhidazbaov fomuvrkp bcoy fvi gjoph bozwuic rcoelawq of ardinf, yio tur kihuruckt opbefm homyenh eb fnu ceqe cor. Qefuyabc a xubtip ay e vduvv hapz die juvl ij yoqupmdf ncir DeytavqdHehtotb.phiocuVobcihDidgewq(:::).
Qut, iws cyo izmgulobvahiaz ox eesq kuyyliix yy kegdapv bra zogyhcovpafw ix nbu xyulv mfbug:
public class func createPersonContact(
firstName: String,
lastName: String,
phoneNumber: String
) -> ContactCard {
PersonContactCard(firstName: firstName, lastName: lastName, phoneNumber: phone) // new code
}
public class func createCompanyContact(
companyName: String,
phoneNumber: String
) -> ContactCard {
CompanyContactCard(companyName: companyName, phoneNumber: phone) // new code
}
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.