1+ [ ![ Dev] ( https://img.shields.io/badge/docs-dev-blue.svg )] ( https://github.com/rjplevin/Classes.jl/blob/master/docs/src/index.md )
12[ ![ Build Status] ( https://travis-ci.org/rjplevin/Classes.jl.svg?branch=master )] ( https://travis-ci.org/rjplevin/Classes.jl )
2- [ ![ Build status] ( https://ci.appveyor.com/api/projects/status/github/rjplevin/Classes.jl?branch=master&?svg=true )] ( https://ci.appveyor.com/project/rjplevin/classes-jl/branch/master )
33[ ![ codecov] ( https://codecov.io/gh/rjplevin/Classes.jl/branch/master/graph/badge.svg )] ( https://codecov.io/gh/rjplevin/Classes.jl )
44[ ![ Coverage Status] ( https://img.shields.io/coveralls/github/rjplevin/Classes.jl/master.svg )] ( https://coveralls.io/github/rjplevin/Classes.jl?branch=master )
55
@@ -13,18 +13,18 @@ If multiple types need to share structure, you have several options:
13131 . Write out the common fields manually.
14141 . Write a macro that emits the common fields. This is better than the manual approach
1515 since it creates a single point of modification.
16- 1 . Use composition instead of inheritance: create a new type that holds the common fields
16+ 1 . Use composition instead of inheritance: create a new type that holds the common fields
1717 and include an instance of this in each of the structs that needs the common fields.
18181 . Use an existing package that provides the required features.
1919
2020All of these have downsides:
2121
22- * As suggested above, writing out the duplicate fields manually creates maintenance challenges
22+ * As suggested above, writing out the duplicate fields manually creates maintenance challenges
2323 since you no longer have a single point of modification.
2424* Using a macro to emit the common fields solves this problem, but there's still
2525 no convient way to identify the relatedness of the structs that contain these common fields.
26- * Composition -- the typically recommended julian approach -- generally involves creating
27- functions to delegate from the outer type to the inner type. This can become tedious if
26+ * Composition -- the typically recommended julian approach -- generally involves creating
27+ functions to delegate from the outer type to the inner type. This can become tedious if
2828 you have multiple levels of nesting. Of course you
2929 can write forwarding macros to handle this, but this also becomes repetitive.
3030* Neither of the packages I reviewed -- OOPMacro.jl and ConcreteAbstractions.jl -- combine the
@@ -41,8 +41,8 @@ generated abstract types. The `@class` macro saves the field definitions for eac
4141so that subclasses receive all their parent's fields in addition to those defined locally.
4242Inner constructors are passed through unchanged.
4343
44- ` Classes.jl ` constructs a "shadow" abstract type hierarchy to represent the relationships among
45- the defined classes. For each class ` Foo ` , the abstract type ` AbstractFoo ` is defined, where ` AbstractFoo `
44+ ` Classes.jl ` constructs a "shadow" abstract type hierarchy to represent the relationships among
45+ the defined classes. For each class ` Foo ` , the abstract type ` AbstractFoo ` is defined, where ` AbstractFoo `
4646is a subtype of the abstract type associated with the superclass of ` Foo ` .
4747
4848Given these two class definitions (note that ` Class ` is defined in ` Classes.jl ` ):
5959end
6060```
6161
62- The following julia code is emitted:
62+ The following julia code is emitted for this example:
63+
64+ <details >
65+
66+ <summary >Macroexpand</summary >
6367
6468``` julia
6569abstract type AbstractFoo <: AbstractClass end
@@ -95,7 +99,10 @@ mutable struct Bar{} <: AbstractBar
9599end
96100```
97101
98- Note that the second emitted constructor is parameterized such that it can be called
102+ </details >
103+ <br />
104+
105+ Note that the second emitted constructor is parameterized such that it can be called
99106on the class's subclasses to set fields defined by the class. Of course, this is
100107callable only on a mutable struct.
101108
@@ -110,11 +117,11 @@ Classes.issubclass(::Type{Bar}, ::Type{Foo}) = true
110117
111118Adding the ` mutable ` keyword after ` @class ` results in a mutable struct, but this
112119feature is not inherited by subclasses; it must be specified (if desired) for each
113- subclass. ` Classes.jl ` offers no special handling of mutability: it is the user's
114- responsibility to ensure that combinations of mutable and immutable classes and related
120+ subclass. ` Classes.jl ` offers no special handling of mutability: it is the user's
121+ responsibility to ensure that combinations of mutable and immutable classes and related
115122methods make sense.
116123
117- ## Defining methods to operate on a class hierarchy
124+ ## Defining methods to operate on a class hierarchy
118125
119126To define a function that operates on a class and its subclasses, specify the
120127associated abstract type rather than the class name in the method signature.
0 commit comments