GithubHelp home page GithubHelp logo

lawrencelomax / llcomposite Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 317 KB

A library that uses the Objective-C runtime to compose objects from variant components

License: MIT License

C++ 0.02% C 50.29% Ruby 0.21% Shell 0.16% Objective-C 28.34% Assembly 20.99%

llcomposite's Introduction

NOTE THAT THIS IS HEAVILY WIP AND SHOULD LIKELY NOT BE USED IN PRODUCTION CODE UNTIL IT IS COMPLETED AND TESTED

Introduction

This is my attempt at a implementation of the Object Composition Pattern in Objective-C. It is intended to be as Lightweight and Simple as possible, whilst requiring minimal configuration.

Usage

Just add the Classes to your XCode project and add an import for NSObject+LLComposite.h in any classes that you wish to use composition. The easiest way of using this in all of your classes without #imports in each of them is to add the import in the prefix header.

A component can be any Instance of an Object and added via the -addComponent: Method. This will add the component to each instance individually. If you wish to add a component to all instances, I suggest that you do this in the constructor of the object.

You can adopt to explicity use the class LLCompositeForwarder to perform forwarding of methods, however

Gotchas

If you are using the category forwarding then make sure to never override any method ending in __original, _triage or _composite. These are the methods that the category uses in swizzling so that the original implementation of forwarding methods are preserved.

I have not tested the performance. For each Composite object that adds a Component with addComponent: One Class and One Mutable Dictionary will be created. This is on a Per-Instance basis. If you think that this is too much of an overhead this (version) of the library is probably not for you.

Performance will also be affected if there are Components that have the same selector. Each selector will be called once per Component instance. This requires that the use of NSInvocation which has additional overhead when compared to a call propogated through the use of the fast forwarding method (this occurs when there is only one component matching the selector).

Implementation Detail

Objective-C is a great language for implementing Composition as the Forwarding of Messages is a language-level feature. class for object compositio n, it uses Objective-C Message Forwarding to allow

TODO

  • Proper (Unit) Testing
  • CococaPod
  • Performance Testing
  • Dynamic Classes for Composites who have identical components

Licence

llcomposite's People

Contributors

lawrencelomax avatar

Watchers

 avatar  avatar

Forkers

mralexgray

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.