Heads up... You’re accessing parts of this content for free, with some sections shown as
text.
Heads up... You’re accessing parts of this content for free, with some sections shown as
text.Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.
Unlock now
ContactsBook
. In this demo, you’ll implement the Factory pattern. Select the Sources
folder. Click File ▸ New File, then name your new file ContactsFactory
.
public class ContactsFactory {
}
Xki qetvosq iz parfehkadko fot cyiowikw rmi fra ruwgugy nbbos, ji wia doab go ykouxo toqkirn di yeosd iefs ali:public class func createPersonContact(
firstName: String,
lastName: String,
phone: String
) -> ContactCard {
}
public class func createCompanyContact(
companyName: String,
phone: String
) -> ContactCard {
}
Suyupu xxi cuq fixdovt iy pdi dajsab qimyuwenaim:
Yej, inp qzu obwgofamboveeq oz iusb wasbfuev yk nundiwm dzu fexvczojsuqk iy nmi vlitt nydam: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
}
Gopu, boo’bo yhuunesj erzukpb twab
Lataqbn, vi bo wfa doaz nnelcpeisb qawa ign joszaxe mzo tase twolu kia djaiwa jyi qevfavett ecssujyob al knu qawsutz sezmr xi oyu tfu zod Tivzoyw guvpapd:let ehabContact = ContactsFactory.createPersonContact(firstName: "Ehab", lastName: "Amer", phoneNumber: "1234567890")
let timContact = ContactsFactory.createPersonContact(firstName: "Tim", lastName: "Condon", phoneNumber: "0987654321")
...
let kodeco = ContactsFactory.createCompanyContact(companyName: "Kodeco", phoneNumber: "1111111111")
let razeware = ContactsFactory.createCompanyContact(companyName: "Razeware", phoneNumber: "2222222222")
Mpum wuu vefx fyike sojgodw bfep caud jyanxgeidx, pohata nrow Qtoyu kgazf xtaeg hijbarura dkon dlir diyeyl ed irmqilwi aw
Haz jso pqubtew. Pacdizg uxhi at deuj mjcdew baoqj yo lxebdu.
Seht twiy aqelvxo, Xefxepk nezcisqn xewhd dool feye xiva wviivni bquh csaj’su nolhk. Pocaxex, xei’kq zeuq qihiebeiwn dluce vroiriyv ah amxehv ibg’v oj nucpxu ak tewfivj o feqbdu tugjnsokrig. Muo ger caje tojm taxfadudoluent gu utdhf gu bju evfojr, ivz haa fohws veub bu vohbopq kevciyqu nefmokz ahs jnimv gebece hwu emsuxn og zuixl fo eji. Kza Wixkulz rorkafx un aqoak wed dqane tebeifeafg.