Comments (5)
Because the API is not fully stabilized yet, I prefer to keep extensibility to a minimum to avoid breaking too much stuff when changing internals. But I would definitely be interested by your use case for extensibility!
About dependency injection, you usually inject services, but not value objects? Why would you ever dependency-inject a BigInteger
? Again, I'm interested by the use case, in case I'm missing something.
A technical note about private constructors.
Private constructors and public factory methods is a strategy I use to speed up object creation. Basically, the private constructor assumes that the input is fully validated, and just copies the information to the private fields. The public factory methods, called by your application, perform the necessary checks and conversions before calling the constructor.
The advantage here is that the methods such as plus()
, minus()
which all return a new object, can directly call the private constructor, as we know for a fact that they output valid information.
If we were to validate things in the constructor, there would be unnecessary validation here, and performance would be affected.
from math.
Thanks of the response.
I wanted to use ur BigInteger & BigDecimal classes but i don't really like
the method names your using.
And my application is already dependent on a Number & Money interface.
So I wanted to extent ur BigDecimal class and add some alias methods to it.
Ur argument for not using dependency injection on ur BigDecimal class is
valid.
But this isn't necessarily the case for my ideal Money class.
I would like to add some service classes to the money object.
To make the Api more easy to use.
Right now its completely impossible to extend your classes or add my own
dependencies.
Side note I'm aware your money class is a value object.
And maybe i shouldn't be adding dependencies to it.
But this is just a special use care i have.
2015-09-05 14:29 GMT+02:00 Benjamin Morel [email protected]:
Because the API is not fully stabilized yet, I prefer to keep
extensibility to a minimum to avoid breaking too much stuff when changing
internals. But I would definitely be interested by your use case for
extensibility!About dependency injection, you usually inject services, but not value
objects? Why would you ever dependency-inject a BigInteger? Again, I'm
interested by the use case, in case I'm missing something.A technical note about private constructors.
Private constructors and public factory methods is a strategy I use to
speed up object creation. Basically, the private constructor assumes that
the input is fully validated, and just copies the information to the
private fields. The public factory methods, called by your application,
perform the necessary checks and conversions before calling the constructor.The advantage here is that the methods such as plus(), minus() which all
return a new object, can directly call the private constructor, as we know
for a fact that they output valid information.If we were to validate things in the constructor, there would be
unnecessary validation here, and performance would be affected.—
Reply to this email directly or view it on GitHub
#2 (comment).
from math.
But one of my use cases requires me to have extendability
Could you elaborate on why you need to extend those classes? Have you considered extending BigNumber
and wrapping e.g. BigInteger
instead of extending it?
from math.
What you are searching for is object composition: https://en.m.wikipedia.org/wiki/Object_composition
from math.
@jkuchar is right, if you don't like the API, you can use composition instead of inheritance and create your own API on top of it.
That's what I've done with brick/phonenumber, that's based on giggsey/libphonenumber-for-php, for example: I didn't like the fact that the original PhoneNumber
implementation was mutable, and a few other things, so I've composed my own PhoneNumber implementation on top of it.
You're welcome to do the same here!
from math.
Related Issues (20)
- brick/math method for gmp_random_range HOT 4
- brick/math method for gmp_invert HOT 8
- The given value ".1200" does not represent a valid number. HOT 2
- Add a changelog HOT 3
- Rounding error on exactlyDividedBy() HOT 2
- Fatal error: Maximum execution time of 30 seconds exceeded HOT 2
- RFC: add `getPrecision` method. HOT 11
- Issue with dividedBy and MultipliedBy? HOT 3
- Feature Request: Implement lisachenko/z-engine HOT 1
- BigComplex HOT 2
- How to accept any scale without rounding HOT 1
- Accept hexadecimal input HOT 1
- Rounding is necessary to represent the result of the operation at this scale. HOT 2
- [0.10.0] behavior change HOT 1
- Please support php8.1 HOT 1
- Implements the Serializable interface, which is deprecated HOT 1
- `gmp_export` equivalent HOT 6
- Rounding bug, or am I just dumb? HOT 4
- Output a BigRational in decimal form with period
- Implement `__debugInfo` magic method HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from math.