-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactoryDesignPattern
More file actions
42 lines (37 loc) · 833 Bytes
/
FactoryDesignPattern
File metadata and controls
42 lines (37 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function standardMembership () {
return {
playSongs() {
console.log('Playing songs...');
console.log('Why dont you try our premium subscrpition?? wala ad');
console.log('Continues playing songs');
},
getCost() {
return 0;
}
}
}
function premiumMembership () {
return {
playSongs() {
console.log('Playing songs without ads! Enjoy!');
} ,
getCost() {
return 199;
}
}
}
function MemberFactory () {
return {
createMembership : function(type) {
if(type === 'premium') {
return premiumMembership();
} else {
return standardMembership();
}
}
}
}
const member1 = MemberFactory().createMembership('standard');
member1.playSongs();
const member2 = MemberFactory().createMembership('premium');
member2.playSongs();