Giter Site home page Giter Site logo

Subclassing Workbook about workbook HOT 1 CLOSED

murb avatar murb commented on July 23, 2024
Subclassing Workbook

from workbook.

Comments (1)

murb avatar murb commented on July 23, 2024

Hmm... I'm not sure whether adding domain logic to what basically is a reader is a good idea (have a look at this talk: http://www.youtube.com/watch?feature=player_embedded&v=WpkDN78P884 ). I would attempt to keep it completely separate from domain logic and use workbook as a gem in your project, not the base of your project (and if you need specific functionality think whether it belongs in this gem or not (and in the case of StringIO it does fit)). However, if you still feel there is a need... I kind of think there is a smell to the first option with splitting names on '::' that I don't like... I would be ok with taking patches for option 2 but I'd first reconsider whether adding domain logic is a good thing in the first place (you can mail me if you prefer).

Op 12 apr. 2013, om 20:22 heeft kianw [email protected] het volgende geschreven:

One thing I was mulling over was how to subclass Workbook in order to add domain-specific functionality to the classes. I didn't want to monkey-patch your classes, as we may need more than one domain with different functionality, so subclassing seems the way to go.

The issue I was running into was that if I subclass Workbook::Book and Workbook::Sheet, for example, my Workbook::Book subclass will still use the super-classes, such as creating a Workbook::Sheet in #initialize or #push (instead of my new Sheet subclass). Short of overriding every method that references one of the other Workbook classes (ugh), there doesn't appear to be any way to easily do this right now (maybe I'm missing something obvious?).

Two solutions spring to mind: 1) create a new module for each domain, with classes that inherit from Workbook classes. And modify Workbook so that every reference to the Workbook constant is changed to something like self.class.const_get(self.class.name.split('::')[0..-2].join), which would get the module for self. We'd probably put that code in a helper method.

Or 2) replace (in Workbook) every reference to a Workbook class constant (e.g., Workbook::Sheet) with a call to a helper method that returns the class constant. Then when you subclass a Workbook class, you just need to override those helper methods to point to your subclasses instead of the base Workbook classes.

These options are fairly similar; option 1 has the advantage of putting the subclasses into a new module (although you could do that with option 2 also), and it doesn't require you to override any methods. option 2 is probably a bit simpler.

Any ideas or feedback?


Reply to this email directly or view it on GitHub.

from workbook.

Related Issues (11)

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.