Last active
July 18, 2019 14:22
-
-
Save mosdevly/c5961b4c6943ac5268376bc16cb8017a to your computer and use it in GitHub Desktop.
Revisions
-
Proto revised this gist
Jul 18, 2019 . 2 changed files with 20 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ """Open/Closed Principle Example inspired by this wonderful piece here: http://joelabrahamsson.com/a-simple-example-of-the-openclosed-principle/ """ # Area calculator: calculate area of a rectangle class Rectangle: def __init__(self, width, height): self.width = width self.height = height def area(self): return self.width * self.height # Calculate area of multiple rectangles class AreaCalculator:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,3 +39,6 @@ def __init__(self, radius): def area(self): import math return (self.radius**2)*math.pi class AreaCalculator: def calculate(self, shapes):
-
Proto revised this gist
Jul 18, 2019 . 2 changed files with 41 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ """ Single Responsibility Principle Every module, class, or function should have responsibility over a single part of the functionality provided by the software. User class handles one thing: the identity of a user. It's sole method does exactly 1 thing: changes the name property. """ class User: id = 1; name = ''; def updateName(newName): this.name = newName console.log('Name updated.') """Open/Closed Principle Example inspired by this wonderful piece here: http://joelabrahamsson.com/a-simple-example-of-the-openclosed-principle/ """ class Shape: def area(self): NotImplementedError('You must implement this method!') class Rectangle(Shape): def __init__(self, width, height): self.width = width self.height = height def area(self): return self.width * self.height class Circle(Shape): def __init__(self, radius): self.radius = radius def area(self): import math return (self.radius**2)*math.pi -
Proto revised this gist
Jul 18, 2019 . 2 changed files with 15 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ """ Single Responsibility Principle Every module, class, or function should have responsibility over a single part of the functionality provided by the software. User class handles one thing: the identity of a user. It's sole method does exactly 1 thing: changes the name property. """ class User: id = 1; name = ''; def updateName(newName): this.name = newName console.log('Name updated.') -
Proto revised this gist
Jul 18, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,9 +3,9 @@ * @desc every module, class, or function should have responsibility over a single part * of the functionality provided by the software. * * User class handles one thing: the identity of a user. It's sole method does exactly 1 thing: changes the name property. */ class User { id = 1; name = ''; -
Proto revised this gist
Jul 18, 2019 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,12 @@ /** * Single Responsibilit Principle * @desc every module, class, or function should have responsibility over a single part * of the functionality provided by the software. * * Person class handles one thing: the identity of a person. It's sole method does exactly 1 thing: changes the name property. */ class Person { id = 1; name = ''; updateName(newName) { -
Proto created this gist
Jul 18, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ class Person { name = ''; updateName(newName) { this.name = newName console.log('Name updated.') } {