Code Monkey home page Code Monkey logo

design-patterns-in-swift's People

Contributors

aakiffrt avatar actions-user avatar binlogo avatar codestergit avatar codethought avatar codethought2 avatar cozzin avatar delebedev avatar divinedominion avatar expdorriss avatar fjbelchi avatar jleft avatar jonstaff avatar jpotts18 avatar kingreza avatar markthethomas avatar michalkonturek avatar minsone avatar mohamedmostafafawzi avatar neoneye avatar ochococo avatar sammy-sc avatar sookim-1 avatar tavernari avatar thedmitry avatar tomkowz avatar viniciusml avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

design-patterns-in-swift's Issues

Observer pattern is not observer

The observer pattern is acting like one. When setting new values, information should be invoked in observer object not in object that is observer. In fact it is acting like normal setter.

UML diagrams

Hi,
Thanks for a great work and excellent samples. If you can add UML diagrams to every pattern it will be nice.

Singleton pattern might need a bit more to have it right..

To ensure that one and ONLY one instance of a class is created, there should be a bit more than just having a public shared instance. One have to ensure that nobody else can create another instance by making the initializer private. So, the example might be extended as follows:

class DeathStarSuperlaser {
    static let sharedInstance = DeathStarSuperlaser()

    private init(){
     // Do something ...
   }
}

NOTE: In the playground the private scope might not be respected, since I could create instances of my singleton class even if the initializer was private, but in the "real" code I get the error "'DeathStarSuperlaser' cannot be constructed because it has no accessible initializers", when I try to crate an instance of my singleton by calling the initializer like this: let anotherLaser = DeathStarSuperlaser()

Lose call flow in mediator example

In Mediator case, just have the MessageMediator broadcast the message to all Programmers. But In GOF, mediator structure like below:

521bcedd-4c0b-4d63-8d51-ecb1f38b16e1

Apparently, programmers need to communicate with each other, so they also need to hold the MessageMediator.
Looking forward to your reply, thanks.

Add Flyweight pattern

There are 3 more patterns from the classical GOF collection that are missing.
I will open a separate issue for each of them and send a pull request to add those too sometime this week.

Some wrong in the Mediator Example

class MessageMediator: Mediator {
private var colleagues: [Colleague] = []

func addColleague(colleague: Colleague) {
    colleagues.append(colleague)
}

func send(message: String, colleague: Colleague) {
    for c in colleagues {
        if c !== colleague { //for simplicity we compare object references
            colleague.receive(message)
        }
    }
}

}

It should be c.receive(message) :-)

Invalid sorting in Table of Contents

Table of Contents in README.md has invalid sorting, in Behavioral section (Visitor pattern should be after Template Method pattern)

πŸ“· Screenshot

Screenshot 2023-06-29 at 21 56 45

Add a table of contents for convenience.

Readme is getting longer and longer

Hi,

At first I want to thanks for this repo, it's great for people who want to read about design patterns in swift and it is good for me, for learning others by contributing and sharing our knowledge and for learning myself when I'm wiring examples of some patterns :)

What this issue is about is maintenance Readme.markdown file. I was thinking a little bit and I'm afraid this file is bulky, hard to browse and maintenance. Wouldn't it be better to move all the patterns implementations to separated .swift files and create links in description to these files (with some description optionally)?

The file could looks like this:

/// Pattern name
/// Xcode version

/** Short description
description here
*/

/// Implementation
implementation here

/// Usage
One or more use cases

What do you think about the idea?

description

It would be great if we could have better explanation for the patterns as reading entire code to understand what it does is rather difficult!

Improve readability in `./source/behavioral/chain_of_responsibility.swift`

./source/behavioral/chain_of_responsibility.swift has an opportunity to improve readability.

Consider this snippet from the file:

if let next = self.next {
    return next.withdraw(amount: amount)
}

That could be rewritten as:

if let next {
    return next.withdraw(amount: amount)
}

Though, it requires newer version of the Swift programming language.

Monostate pattern example can not build

Monostate example code has build issue.

And it uses struct, since struct is "copy" semantics, which is not the good way to share singularity state.

struct Settings {

    enum Theme {
        case .old // build error
        case .new // build error
    }

    private static var theme: Theme // build error

    var currentTheme: Theme {
        get { Settings.theme }
        set(newTheme) { Settings.theme = newTheme }
    }
}

Reasoning behind BuilderClosure

What is the reasoning behind having the BuilderClosure in the implementation of the Builder pattern?

 typealias BuilderClosure = (DeathStarBuilder) -> ()

    init(buildClosure: BuilderClosure) {
        buildClosure(self)
    }

I don't recall seeing this when working with the Builder pattern in other languages and my code works without it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.