{"id":20035918,"url":"https://github.com/rafaelfgx/objectorientedprogramming","last_synced_at":"2025-06-10T11:33:39.114Z","repository":{"id":39482374,"uuid":"203687756","full_name":"rafaelfgx/ObjectOrientedProgramming","owner":"rafaelfgx","description":"Object-Oriented Programming.","archived":false,"fork":false,"pushed_at":"2024-11-12T21:13:31.000Z","size":7,"stargazers_count":24,"open_issues_count":0,"forks_count":12,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-11-12T22:22:00.315Z","etag":null,"topics":["oop","oop-principles"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rafaelfgx.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-22T01:00:24.000Z","updated_at":"2024-11-12T21:13:34.000Z","dependencies_parsed_at":"2024-06-27T17:26:45.955Z","dependency_job_id":"49f2ae79-060a-4cf2-984b-eabdeeef7e97","html_url":"https://github.com/rafaelfgx/ObjectOrientedProgramming","commit_stats":null,"previous_names":["rafaelfgx/objectorientedprogramming"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelfgx%2FObjectOrientedProgramming","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelfgx%2FObjectOrientedProgramming/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelfgx%2FObjectOrientedProgramming/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelfgx%2FObjectOrientedProgramming/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rafaelfgx","download_url":"https://codeload.github.com/rafaelfgx/ObjectOrientedProgramming/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224427847,"owners_count":17309373,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["oop","oop-principles"],"created_at":"2024-11-13T10:09:56.634Z","updated_at":"2024-11-13T10:09:57.209Z","avatar_url":"https://github.com/rafaelfgx.png","language":"C#","readme":"# Object-Oriented Programming\n\n## Pillars\n\n### Abstraction\n\nAbstraction is to turn real world objects, properties, and behaviors into a computational representation.\n\n### Encapsulation\n\nEncapsulation is to protect internal properties and behaviors of an object from being manipulated externally.\n\n### Inheritance\n\nInheritance is to reuse properties and behaviors of a base class by a derived class.\n\n### Polymorphism\n\nPolymorphism is the ability of an object to assume and be used as other forms.\n\n## Examples\n\n### Animal\n\n```cs\npublic abstract record Animal(string Name)\n{\n    public bool Sleeping { get; private set; }\n\n    public string Drink() =\u003e \"Drink\";\n\n    public string Eat() =\u003e \"Eat\";\n\n    public virtual string Move() =\u003e \"Move\";\n\n    public abstract string Sound();\n\n    public void Awake() =\u003e Sleeping = false;\n\n    public void Sleep() =\u003e Sleeping = true;\n}\n```\n\n```cs\npublic sealed record Cat : Animal\n{\n    public Cat() : base(nameof(Cat)) { }\n\n    public override string Sound() =\u003e \"Meow\";\n}\n```\n\n```cs\npublic sealed record Dog : Animal\n{\n    public Dog() : base(nameof(Dog)) { }\n\n    public override string Sound() =\u003e \"Bark\";\n}\n```\n\n```cs\npublic sealed record Duck : Animal\n{\n    public Duck() : base(nameof(Duck)) { }\n\n    public override string Move() =\u003e \"Swim\";\n\n    public override string Sound() =\u003e \"Quack\";\n}\n```\n\n```cs\npublic sealed record Eagle : Animal\n{\n    public Eagle() : base(nameof(Eagle)) { }\n\n    public override string Move() =\u003e \"Fly\";\n\n    public override string Sound() =\u003e \"Screech\";\n}\n```\n\n```cs\npublic sealed record Lion : Animal\n{\n    public Lion() : base(nameof(Lion)) { }\n\n    public override string Sound() =\u003e \"Roar\";\n}\n```\n\n```cs\npublic sealed record Snake : Animal\n{\n    public Snake() : base(nameof(Snake)) { }\n\n    public override string Sound() =\u003e \"Hiss\";\n}\n```\n\n### Notification\n\n```cs\npublic interface IMessage { }\n```\n\n```cs\npublic sealed record EmailMessage(string To, string Body, string Subject) : IMessage;\n```\n\n```cs\npublic sealed record SmsMessage(string To, string Body) : IMessage;\n```\n\n```cs\npublic interface INotification\u003cTMessage\u003e where TMessage : IMessage\n{\n    void Notify(TMessage message);\n}\n```\n\n```cs\npublic sealed class EmailNotification : INotification\u003cEmailMessage\u003e\n{\n    public void Notify(EmailMessage message) =\u003e Console.WriteLine(nameof(EmailNotification));\n}\n```\n\n```cs\npublic sealed class SmsNotification : INotification\u003cSmsMessage\u003e\n{\n    public void Notify(SmsMessage message) =\u003e Console.WriteLine(nameof(SmsNotification));\n}\n```\n\n### Payment\n\n```cs\npublic interface IPayment\n{\n    void Pay(decimal value);\n}\n```\n\n```cs\npublic sealed class Cash : IPayment\n{\n    public void Pay(decimal value) =\u003e Console.WriteLine(nameof(Cash));\n}\n```\n\n```cs\npublic sealed class CreditCard : IPayment\n{\n    public void Pay(decimal value) =\u003e Console.WriteLine(nameof(CreditCard));\n}\n```\n\n```cs\npublic sealed class DebitCard : IPayment\n{\n    public void Pay(decimal value) =\u003e Console.WriteLine(nameof(DebitCard));\n}\n```\n\n```cs\npublic sealed class PaymentService\n{\n    public PaymentService(IPayment payment) =\u003e Payment = payment;\n\n    private IPayment Payment { get; }\n\n    public void Pay(decimal value) =\u003e Payment.Pay(value);\n}\n```\n\n### Repositories\n\n```cs\npublic interface IRepository\u003cT\u003e\n{\n    void Insert(T entity);\n\n    IEnumerable\u003cT\u003e List();\n\n    T Select(int id);\n\n    void Update(T entity);\n}\n```\n\n```cs\npublic abstract class MySqlRepository\u003cT\u003e : IRepository\u003cT\u003e\n{\n    public void Insert(T entity) { }\n\n    public IEnumerable\u003cT\u003e List() =\u003e new List\u003cT\u003e();\n\n    public T Select(int id) =\u003e default;\n\n    public void Update(T entity) { }\n}\n```\n\n```cs\npublic abstract class SqlServerRepository\u003cT\u003e : IRepository\u003cT\u003e\n{\n    public void Insert(T entity) { }\n\n    public IEnumerable\u003cT\u003e List() =\u003e new List\u003cT\u003e();\n\n    public T Select(int id) =\u003e default;\n\n    public void Update(T entity) { }\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafaelfgx%2Fobjectorientedprogramming","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafaelfgx%2Fobjectorientedprogramming","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafaelfgx%2Fobjectorientedprogramming/lists"}