[ 
https://issues.apache.org/jira/browse/NUMBERS-123?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16877335#comment-16877335
 ] 

Heinrich Bohne commented on NUMBERS-123:
----------------------------------------

I just googled a bit about factory methods vs constructors, and it turns out 
there are indeed some differences between the two that I had not considered 
before, so now I understand your preference for factory methods a bit better.

With this renewed perspective on the issue, I think that the most "consistent" 
design would really be to strip the constructor of _all_ validation 
responsibilities and reduce it to a mere input interface that simply accepts 
arguments and assigns them to the fields (which is the only thing that _must_ 
be done inside a constructor and not a factory method, because a static factory 
method cannot do that). When viewing the purpose of a constructor this way, 
there can, by definition, not be more than one constructor.

But, as I said, this is not really of great importance, I just wanted to share 
the thought.

> "BigFraction(double)" is unnecessary
> ------------------------------------
>
>                 Key: NUMBERS-123
>                 URL: https://issues.apache.org/jira/browse/NUMBERS-123
>             Project: Commons Numbers
>          Issue Type: Improvement
>          Components: fraction
>            Reporter: Gilles
>            Assignee: Gilles
>            Priority: Trivial
>             Fix For: 1.0
>
>         Attachments: NUMBERS-123__Javadoc.patch
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Constructor {{BigFraction(double value)}} is only called from the 
> {{from(double value)}} method.
>  Actually, this constructor is misleading as it is indeed primarily a 
> conversion from which appropriate {{numerator}} and {{denominator}} fields 
> are computed; those could be set by
>  the "direct" constructor {{BigFraction(BigInteger num, BigInteger den)}}.
> Moreover, the private field {{ZERO}} goes through this conversion code 
> whereas it could constructed "directly", e.g. using {{of(0)}}. Similarly for 
> field {{ONE}}.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to