├── dependecyInversion.js ├── dependecyInversion.ts ├── dependecyInversion2.js ├── dependecyInversion2.ts ├── dependecyInversion3.js ├── dependecyInversion3.ts ├── liskov.ts ├── liskov2.js ├── liskov2.ts ├── logger.js ├── logger.ts ├── loggerLong.js └── loggerLong.ts /dependecyInversion.js: -------------------------------------------------------------------------------- 1 | var ManageAdvertisement = /** @class */ (function () { 2 | function ManageAdvertisement() { 3 | this.banner = new Banner(); 4 | this.video = new Video(); 5 | } 6 | ManageAdvertisement.prototype.Show = function () { 7 | this.banner.ShowBanner(); 8 | this.video.ShowVideo(); 9 | }; 10 | return ManageAdvertisement; 11 | }()); 12 | var Banner = /** @class */ (function () { 13 | function Banner() { 14 | } 15 | Banner.prototype.ShowBanner = function () { console.log("Show Banner"); }; 16 | return Banner; 17 | }()); 18 | var Video = /** @class */ (function () { 19 | function Video() { 20 | } 21 | Video.prototype.ShowVideo = function () { console.log("Show Video"); }; 22 | return Video; 23 | }()); 24 | var mng = new ManageAdvertisement(); 25 | mng.Show(); 26 | -------------------------------------------------------------------------------- /dependecyInversion.ts: -------------------------------------------------------------------------------- 1 | class ManageAdvertisement { 2 | banner: Banner; 3 | video: Video; 4 | 5 | constructor() { 6 | this.banner = new Banner() 7 | this.video = new Video() 8 | } 9 | 10 | public Show() { 11 | this.banner.ShowBanner(); 12 | this.video.ShowVideo(); 13 | } 14 | } 15 | 16 | class Banner { 17 | public ShowBanner() {console.log("Show Banner"); } 18 | } 19 | 20 | class Video { 21 | public ShowVideo() {console.log("Show Video"); } 22 | } 23 | 24 | var mng=new ManageAdvertisement(); 25 | mng.Show(); -------------------------------------------------------------------------------- /dependecyInversion2.js: -------------------------------------------------------------------------------- 1 | var Banner = /** @class */ (function () { 2 | function Banner() { 3 | } 4 | Banner.prototype.Show = function () { return "Banner Showed!"; }; 5 | return Banner; 6 | }()); 7 | var Video = /** @class */ (function () { 8 | function Video() { 9 | } 10 | Video.prototype.Show = function () { return "Video Showed!"; }; 11 | return Video; 12 | }()); 13 | var Advertisment = /** @class */ (function () { 14 | function Advertisment(advertisment) { 15 | this._advertisment = advertisment; 16 | } 17 | Advertisment.prototype.Show = function () { 18 | console.log(this._advertisment.Show()); 19 | }; 20 | return Advertisment; 21 | }()); 22 | var AdvertismentBanner; 23 | var AdvertismentVideo; 24 | AdvertismentBanner = new Advertisment(new Banner()); 25 | AdvertismentBanner.Show(); 26 | AdvertismentVideo = new Advertisment(new Video()); 27 | AdvertismentVideo.Show(); 28 | -------------------------------------------------------------------------------- /dependecyInversion2.ts: -------------------------------------------------------------------------------- 1 | interface IAdvertisment { 2 | Show(); 3 | } 4 | class Banner implements IAdvertisment { 5 | public Show(): string { return "Banner Showed!"; } 6 | } 7 | class Video implements IAdvertisment { 8 | public Show(): string { return "Video Showed!"; } 9 | } 10 | 11 | class Advertisment { 12 | _advertisment: IAdvertisment; 13 | constructor(advertisment: IAdvertisment) { this._advertisment = advertisment; } 14 | public Show(): void { 15 | console.log(this._advertisment.Show()); 16 | } 17 | } 18 | 19 | var AdvertismentBanner: Advertisment; 20 | var AdvertismentVideo: Advertisment; 21 | AdvertismentBanner = new Advertisment(new Banner()); 22 | AdvertismentBanner.Show(); 23 | AdvertismentVideo = new Advertisment(new Video()); 24 | AdvertismentVideo.Show(); -------------------------------------------------------------------------------- /dependecyInversion3.js: -------------------------------------------------------------------------------- 1 | var __extends = (this && this.__extends) || (function () { 2 | var extendStatics = function (d, b) { 3 | extendStatics = Object.setPrototypeOf || 4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 5 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; 6 | return extendStatics(d, b); 7 | }; 8 | return function (d, b) { 9 | if (typeof b !== "function" && b !== null) 10 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); 11 | extendStatics(d, b); 12 | function __() { this.constructor = d; } 13 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 14 | }; 15 | })(); 16 | var AbstractVideo = /** @class */ (function () { 17 | function AbstractVideo(duration) { 18 | this._duration = String(duration); 19 | } 20 | Object.defineProperty(AbstractVideo.prototype, "Duration", { 21 | get: function () { 22 | return this._duration; 23 | }, 24 | set: function (v) { 25 | this._duration = v; 26 | }, 27 | enumerable: false, 28 | configurable: true 29 | }); 30 | return AbstractVideo; 31 | }()); 32 | var Banner = /** @class */ (function () { 33 | function Banner() { 34 | } 35 | Banner.prototype.Show = function () { return "Banner Showed!"; }; 36 | return Banner; 37 | }()); 38 | var Video = /** @class */ (function (_super) { 39 | __extends(Video, _super); 40 | function Video(duration) { 41 | return _super.call(this, duration) || this; 42 | } 43 | Video.prototype.Show = function () { return "Video Showed! Duration:" + this.Duration; }; 44 | return Video; 45 | }(AbstractVideo)); 46 | var Advertisment = /** @class */ (function () { 47 | function Advertisment(advertisment) { 48 | this._advertisment = advertisment; 49 | } 50 | Advertisment.prototype.Show = function () { 51 | console.log(this._advertisment.Show()); 52 | }; 53 | return Advertisment; 54 | }()); 55 | var AdvertismentVideo = /** @class */ (function () { 56 | function AdvertismentVideo(advertisment) { 57 | this._advertisment = advertisment; 58 | } 59 | AdvertismentVideo.prototype.Show = function () { 60 | console.log(this._advertisment.Show()); 61 | }; 62 | return AdvertismentVideo; 63 | }()); 64 | var AdvertismentBanner; 65 | var AdvVideo; 66 | AdvertismentBanner = new Advertisment(new Banner()); 67 | AdvertismentBanner.Show(); 68 | AdvVideo = new AdvertismentVideo(new Video(15)); 69 | AdvVideo.Show(); 70 | -------------------------------------------------------------------------------- /dependecyInversion3.ts: -------------------------------------------------------------------------------- 1 | interface IAdvertisment { 2 | Show(); 3 | } 4 | 5 | abstract class AbstractVideo { 6 | constructor(duration: number){this._duration=String(duration);} 7 | private _duration: string; 8 | public get Duration(): string { 9 | return this._duration; 10 | } 11 | public set Duration(v: string) { 12 | this._duration = v; 13 | } 14 | } 15 | 16 | class Banner implements IAdvertisment { 17 | public Show(): string { return "Banner Showed!"; } 18 | } 19 | 20 | class Video extends AbstractVideo implements IAdvertisment { 21 | constructor(duration: number){ 22 | super(duration) 23 | } 24 | public Show(): string { return "Video Showed! Duration:" + this.Duration; } 25 | } 26 | 27 | class Advertisment { 28 | _advertisment: IAdvertisment; 29 | constructor(advertisment: IAdvertisment) { this._advertisment = advertisment; } 30 | public Show(): void { 31 | console.log(this._advertisment.Show()); 32 | } 33 | } 34 | 35 | class AdvertismentVideo implements Advertisment { 36 | _advertisment: Video; 37 | constructor(advertisment: Video) { this._advertisment = advertisment; } 38 | public Show(): void { 39 | console.log(this._advertisment.Show()); 40 | } 41 | } 42 | 43 | var AdvertismentBanner: Advertisment; 44 | var AdvVideo: AdvertismentVideo; 45 | AdvertismentBanner = new Advertisment(new Banner()); 46 | AdvertismentBanner.Show(); 47 | AdvVideo = new AdvertismentVideo(new Video(15)); 48 | AdvVideo.Show(); -------------------------------------------------------------------------------- /liskov.ts: -------------------------------------------------------------------------------- 1 | interface ILogin { 2 | DomainLogin() : string; 3 | SocialLogin() : string; 4 | } 5 | 6 | class PortalLogin implements ILogin{ 7 | userName: string; 8 | password: string; 9 | constructor(LoginName: string, LoginPassword: string) { 10 | this.userName = LoginName; 11 | this.password = LoginPassword; 12 | } 13 | DomainLogin() : string{return "Portal Domain Log"}; 14 | SocialLogin() : string{return "Portal Social Log"}; 15 | } 16 | 17 | class FacebookLogin implements ILogin{ 18 | userName: string; 19 | password: string; 20 | constructor(LoginName: string, LoginPassword: string) { 21 | this.userName = LoginName; 22 | this.password = LoginPassword; 23 | } 24 | DomainLogin() : string{return "Facebook Domain Log"}; 25 | SocialLogin() : string{return "Facebook Social Log"}; 26 | } 27 | var faceLogin = new FacebookLogin("Bora", "1234"); 28 | console.log(faceLogin.DomainLogin()); 29 | console.log(faceLogin.SocialLogin()); 30 | 31 | 32 | -------------------------------------------------------------------------------- /liskov2.js: -------------------------------------------------------------------------------- 1 | var __extends = (this && this.__extends) || (function () { 2 | var extendStatics = function (d, b) { 3 | extendStatics = Object.setPrototypeOf || 4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 5 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; 6 | return extendStatics(d, b); 7 | }; 8 | return function (d, b) { 9 | if (typeof b !== "function" && b !== null) 10 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); 11 | extendStatics(d, b); 12 | function __() { this.constructor = d; } 13 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 14 | }; 15 | })(); 16 | var Login = /** @class */ (function () { 17 | function Login(LoginName, LoginPassword) { 18 | this.userName = LoginName; 19 | this.password = LoginPassword; 20 | } 21 | return Login; 22 | }()); 23 | var PortalLogin = /** @class */ (function (_super) { 24 | __extends(PortalLogin, _super); 25 | function PortalLogin(LoginName, LoginPassword) { 26 | return _super.call(this, LoginName, LoginPassword) || this; 27 | } 28 | PortalLogin.prototype.DomainLogin = function () { 29 | if (this.userName == 'Bora' && this.password == "12345") { 30 | return "Wellcome Bora KAŞMER"; 31 | } 32 | else { 33 | return "Your Domain Username or Password Wrong!"; 34 | } 35 | }; 36 | return PortalLogin; 37 | }(Login)); 38 | var SocialLogin = /** @class */ (function (_super) { 39 | __extends(SocialLogin, _super); 40 | function SocialLogin(LoginName, LoginPassword) { 41 | var _this = _super.call(this, LoginName, LoginPassword) || this; 42 | _this.LoginName = LoginName; 43 | _this.LoginPassword = LoginPassword; 44 | return _this; 45 | } 46 | SocialLogin.prototype.DomainLogin = function () { 47 | if (this.userName == 'Bora' && this.password == "12345") { 48 | return "Wellcome Bora KAŞMER"; 49 | } 50 | else { 51 | return "Your Domain Username or Password Wrong!"; 52 | } 53 | }; 54 | SocialLogin.prototype.FaceLogin = function (fbUserName, password) { 55 | if (fbUserName == 'FaceBora' && password == "654321") { 56 | return "Wellcome Facebook Borsoft"; 57 | } 58 | else { 59 | return "Your Facebook Credentials Wrong!"; 60 | } 61 | }; 62 | return SocialLogin; 63 | }(Login)); 64 | var faceLogin = new SocialLogin("Bora", "1234"); 65 | console.log(faceLogin.DomainLogin()); 66 | console.log(faceLogin.FaceLogin("FaceBora", "654321")); 67 | -------------------------------------------------------------------------------- /liskov2.ts: -------------------------------------------------------------------------------- 1 | abstract class Login { 2 | userName: string; 3 | password: string; 4 | constructor(LoginName: string, LoginPassword: string) { 5 | this.userName = LoginName; 6 | this.password = LoginPassword; 7 | } 8 | abstract DomainLogin(): string; 9 | } 10 | 11 | interface IFacebookLogin { 12 | FaceLogin(user: string, password: string): string; 13 | } 14 | 15 | class PortalLogin extends Login{ 16 | constructor(LoginName: string, LoginPassword) { super(LoginName, LoginPassword); } 17 | 18 | DomainLogin(): string { 19 | if (this.userName == 'Bora' && this.password == "12345") { 20 | return "Wellcome Bora KAŞMER"; 21 | } 22 | else { 23 | return "Your Domain Username or Password Wrong!" 24 | } 25 | } 26 | } 27 | 28 | class SocialLogin extends Login implements IFacebookLogin { 29 | constructor(protected LoginName: string, protected LoginPassword) { super(LoginName, LoginPassword); } 30 | 31 | DomainLogin(): string { 32 | if (this.userName == 'Bora' && this.password == "12345") { 33 | return "Wellcome Bora KAŞMER"; 34 | } 35 | else { 36 | return "Your Domain Username or Password Wrong!" 37 | } 38 | } 39 | 40 | FaceLogin(fbUserName: string, password: string): string { 41 | if (fbUserName == 'FaceBora' && password == "654321") { 42 | return "Wellcome Facebook Borsoft"; 43 | } 44 | else { 45 | return "Your Facebook Credentials Wrong!" 46 | } 47 | } 48 | } 49 | 50 | var faceLogin = new SocialLogin("Bora", "1234"); 51 | console.log(faceLogin.DomainLogin()); 52 | console.log(faceLogin.FaceLogin("FaceBora", "654321")); -------------------------------------------------------------------------------- /logger.js: -------------------------------------------------------------------------------- 1 | var XmlLog = /** @class */ (function () { 2 | function XmlLog() { 3 | } 4 | XmlLog.prototype.WriteLog = function () { 5 | return "Xml Log Writer" + new Date().toLocaleDateString(); 6 | }; 7 | return XmlLog; 8 | }()); 9 | var MsSqlLOG = /** @class */ (function () { 10 | function MsSqlLOG() { 11 | } 12 | MsSqlLOG.prototype.WriteLog = function () { 13 | return "MsSql Log Writer" + new Date().toLocaleDateString(); 14 | }; 15 | return MsSqlLOG; 16 | }()); 17 | var MongoLOG = /** @class */ (function () { 18 | function MongoLOG() { 19 | } 20 | MongoLOG.prototype.WriteLog = function () { 21 | return "Mongo Log Writer" + new Date().toLocaleDateString(); 22 | }; 23 | return MongoLOG; 24 | }()); 25 | var LogProcess = /** @class */ (function () { 26 | function LogProcess(logPrc) { 27 | this.logProcess = logPrc; 28 | } 29 | LogProcess.prototype.LogUser = function () { 30 | return this.logProcess.WriteLog(); 31 | }; 32 | return LogProcess; 33 | }()); 34 | var log1 = new LogProcess(new XmlLog()); 35 | console.log(log1.LogUser()); 36 | var log2 = new LogProcess(new MsSqlLOG()); 37 | console.log(log2.LogUser()); 38 | var log3 = new LogProcess(new MongoLOG()); 39 | console.log(log3.LogUser()); 40 | -------------------------------------------------------------------------------- /logger.ts: -------------------------------------------------------------------------------- 1 | interface ILogger { 2 | WriteLog(): string; 3 | } 4 | 5 | class XmlLog implements ILogger { 6 | public WriteLog(): string { 7 | return "Xml Log Writer" + new Date().toLocaleDateString(); 8 | } 9 | } 10 | 11 | class MsSqlLOG implements ILogger { 12 | public WriteLog(): string { 13 | return "MsSql Log Writer" + new Date().toLocaleDateString(); 14 | } 15 | } 16 | 17 | class MongoLOG implements ILogger { 18 | public WriteLog(): string { 19 | return "Mongo Log Writer" + new Date().toLocaleDateString(); 20 | } 21 | } 22 | 23 | class LogProcess { 24 | logProcess: ILogger; 25 | constructor(logPrc: ILogger) { 26 | this.logProcess = logPrc; 27 | } 28 | public LogUser(): string { 29 | return this.logProcess.WriteLog(); 30 | } 31 | } 32 | 33 | var log1 = new LogProcess(new XmlLog()); 34 | console.log(log1.LogUser()); 35 | 36 | var log2 = new LogProcess(new MsSqlLOG()); 37 | console.log(log2.LogUser()); 38 | 39 | var log3 = new LogProcess(new MongoLOG()); 40 | console.log(log3.LogUser()); -------------------------------------------------------------------------------- /loggerLong.js: -------------------------------------------------------------------------------- 1 | var UserType; 2 | (function (UserType) { 3 | UserType[UserType["Mobile"] = 0] = "Mobile"; 4 | UserType[UserType["Console"] = 1] = "Console"; 5 | UserType[UserType["Tablet"] = 2] = "Tablet"; 6 | })(UserType || (UserType = {})); 7 | var User = /** @class */ (function () { 8 | function User() { 9 | } 10 | User.prototype.Talk = function () { 11 | console.log("Hello :".concat(this.LiveID)); 12 | }; 13 | return User; 14 | }()); 15 | var NPC = /** @class */ (function () { 16 | function NPC() { 17 | } 18 | NPC.prototype.Talk = function () { 19 | console.log("Hello :".concat(this.GamerTag)); 20 | }; 21 | return NPC; 22 | }()); 23 | function CreateUser(user, GamerTag, LiveID, UserType, IsGoldMemeber) { 24 | var newUser; 25 | newUser = new user(); 26 | newUser.GamerTag = GamerTag; 27 | newUser.LiveID = LiveID; 28 | newUser.IsGoldMemeber = IsGoldMemeber; 29 | newUser.UserType = UserType; 30 | return newUser; 31 | } 32 | function CreateNPC(npc, GamerTag, LiveID, UserType, Level, VoiceType) { 33 | var newUser; 34 | var newUser = new npc(); 35 | newUser.GamerTag = GamerTag; 36 | newUser.LiveID = LiveID; 37 | newUser.Level = Level; 38 | newUser.VoiceType = VoiceType; 39 | return newUser; 40 | } 41 | var bora; 42 | bora = CreateUser(User, "coderBora", 123, UserType.Console, true); 43 | console.log(bora.GamerTag); 44 | ChatBot(bora); 45 | var pacman; 46 | pacman = CreateNPC(NPC, "PackkMan", 123, UserType.Mobile, 1, 'M'); 47 | console.log(bora.GamerTag); 48 | ChatBot(pacman); 49 | function ChatBot(user) { 50 | user.Talk(); 51 | } 52 | var Greet = /** @class */ (function () { 53 | function Greet(usrType, gmName, usrName) { 54 | this.userType = usrType; 55 | this.gameName = gmName; 56 | this.userName = usrName; 57 | } 58 | Greet.prototype.Greeting = function () { 59 | switch (this.userType) { 60 | case UserType.Mobile: 61 | { 62 | return this.gameName + ": Mobile User " + this.userName; 63 | break; 64 | } 65 | case UserType.Tablet: 66 | { 67 | return this.gameName + ": Tablet User " + this.userName; 68 | break; 69 | } 70 | case UserType.Console: 71 | { 72 | return this.gameName + ": Console User " + this.userName; 73 | break; 74 | } 75 | } 76 | }; 77 | return Greet; 78 | }()); 79 | var Game = /** @class */ (function () { 80 | function Game() { 81 | } 82 | return Game; 83 | }()); 84 | function GameUserLicenses() { 85 | var listOfGameUser = [{ LicenseID: 123457, LiveID: 32147423 }, 86 | { LicenseID: 345632, LiveID: 67432466 }, 87 | { LicenseID: 1111, LiveID: 8244444 }]; // Get Bulk Data From AnyServices 88 | return listOfGameUser; 89 | } 90 | var CheckLicense = /** @class */ (function () { 91 | function CheckLicense() { 92 | } 93 | CheckLicense.prototype.CheckGameLicence = function (Licenses, UserLicenseID, LiveID) { 94 | return (Licenses.filter(function (d) { return d.LicenseID == UserLicenseID && d.LiveID == LiveID; }).length > 0 ? true : false); 95 | }; 96 | return CheckLicense; 97 | }()); 98 | var Verify = /** @class */ (function () { 99 | function Verify(usr, gm) { 100 | this.user = usr; 101 | this.game = gm; 102 | this.greet = new Greet(this.user.UserType, gm.Name, this.user.GamerTag); 103 | this.checkLicense = new CheckLicense(); 104 | } 105 | Verify.prototype.CanJoin = function () { 106 | if (this.user.IsGoldMemeber && 107 | this.checkLicense.CheckGameLicence(GameUserLicenses(), this.game.LicenseID, this.user.LiveID)) { 108 | return "Wellcome to " + this.greet.Greeting(); 109 | } 110 | return "You are not Access " + this.game.Name; 111 | }; 112 | return Verify; 113 | }()); 114 | var usr; 115 | usr = CreateUser(User, "CoderBora", 32147423, UserType.Console, true); 116 | var game = new Game(); 117 | game.LicenseID = 123457; 118 | game.Name = "Tomb Raider"; 119 | var verify = new Verify(usr, game); 120 | console.log(verify.CanJoin()); 121 | -------------------------------------------------------------------------------- /loggerLong.ts: -------------------------------------------------------------------------------- 1 | enum UserType { 2 | Mobile, 3 | Console, 4 | Tablet 5 | } 6 | 7 | interface IUser { 8 | GamerTag: string, 9 | LiveID: number, 10 | UserType: UserType, 11 | Talk(): any 12 | } 13 | 14 | class User implements IUser { 15 | GamerTag: string; 16 | LiveID: number; 17 | UserType: UserType; 18 | IsGoldMemeber: boolean; 19 | Talk() { 20 | console.log(`Hello :${this.LiveID}`) 21 | } 22 | } 23 | 24 | class NPC implements IUser { 25 | Talk() { 26 | console.log(`Hello :${this.GamerTag}`) 27 | } 28 | GamerTag: string; 29 | LiveID: number; 30 | UserType: UserType; 31 | Level: number; 32 | VoiceType: string; 33 | } 34 | 35 | function CreateUser(user: { new(): u; }, GamerTag: string, LiveID: number, UserType: UserType, IsGoldMemeber: boolean) { 36 | var newUser: u; 37 | newUser = new user(); 38 | newUser.GamerTag = GamerTag; 39 | newUser.LiveID = LiveID; 40 | newUser.IsGoldMemeber = IsGoldMemeber; 41 | newUser.UserType = UserType; 42 | return newUser; 43 | } 44 | 45 | function CreateNPC(npc: { new(): n; }, GamerTag: string, LiveID: number, UserType: UserType, Level: number, VoiceType: string) { 46 | var newUser: n; 47 | var newUser = new npc(); 48 | newUser.GamerTag = GamerTag; 49 | newUser.LiveID = LiveID; 50 | newUser.Level = Level; 51 | newUser.VoiceType = VoiceType; 52 | return newUser; 53 | } 54 | 55 | 56 | 57 | var bora: User; 58 | bora = CreateUser(User, "coderBora", 123, UserType.Console, true); 59 | console.log(bora.GamerTag); 60 | ChatBot(bora); 61 | 62 | var pacman: NPC; 63 | pacman = CreateNPC(NPC, "PackkMan", 123, UserType.Mobile, 1, 'M'); 64 | console.log(bora.GamerTag); 65 | ChatBot(pacman); 66 | 67 | function ChatBot(user: IUser) { 68 | user.Talk(); 69 | } 70 | 71 | class Greet { 72 | private userType: UserType; 73 | private userName: string; 74 | private gameName: string; 75 | constructor(usrType: UserType, gmName: string, usrName: string) { 76 | this.userType = usrType; 77 | this.gameName = gmName; 78 | this.userName = usrName; 79 | } 80 | Greeting() { 81 | switch (this.userType) { 82 | case UserType.Mobile: 83 | { 84 | return this.gameName + ": Mobile User " + this.userName; 85 | break; 86 | } 87 | case UserType.Tablet: 88 | { 89 | return this.gameName + ": Tablet User " + this.userName; 90 | break; 91 | } 92 | case UserType.Console: 93 | { 94 | return this.gameName + ": Console User " + this.userName; 95 | break; 96 | } 97 | } 98 | } 99 | } 100 | 101 | class Game { 102 | Name: string; 103 | LicenseID: number; 104 | } 105 | 106 | interface IGameLicencese { 107 | LicenseID: number; 108 | LiveID: number; 109 | } 110 | 111 | function GameUserLicenses(): IGameLicencese[] { 112 | var listOfGameUser = [{ LicenseID: 123457, LiveID: 32147423 }, 113 | { LicenseID: 345632, LiveID: 67432466 }, 114 | { LicenseID: 1111, LiveID: 8244444 }];// Get Bulk Data From AnyServices 115 | return listOfGameUser; 116 | } 117 | 118 | class CheckLicense { 119 | CheckGameLicence(Licenses: L[], UserLicenseID: number, LiveID: number): boolean { 120 | 121 | return (Licenses.filter(d => d.LicenseID == UserLicenseID && d.LiveID == LiveID).length > 0 ? true : false); 122 | } 123 | } 124 | 125 | class Verify { 126 | user: User; 127 | game: Game; 128 | greet: Greet 129 | checkLicense: CheckLicense; 130 | constructor(usr: User, gm: Game) { 131 | this.user = usr; 132 | this.game = gm; 133 | this.greet = new Greet(this.user.UserType, gm.Name, this.user.GamerTag); 134 | this.checkLicense = new CheckLicense(); 135 | } 136 | CanJoin(): string { 137 | if (this.user.IsGoldMemeber && 138 | this.checkLicense.CheckGameLicence(GameUserLicenses(), this.game.LicenseID, this.user.LiveID)) { 139 | return "Wellcome to " + this.greet.Greeting(); 140 | } 141 | return "You are not Access " + this.game.Name; 142 | } 143 | } 144 | 145 | var usr: User; 146 | 147 | usr = CreateUser(User, "CoderBora", 32147423, UserType.Console, true); 148 | var game = new Game(); 149 | game.LicenseID = 123457; 150 | game.Name = "Tomb Raider"; 151 | var verify = new Verify(usr, game); 152 | console.log(verify.CanJoin()); 153 | --------------------------------------------------------------------------------