#Factory design pattern
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
how do i make it so the factori design pattern
can have input from the user
and input it
Please don't return null
And you can't do that indeed
What are you trying to do?
im just practicign
a factori pattenr
i couldnt find an example
so i made on in mu head
tell me an alternative
Throw an exception
You can't just use a design pattern because you want to, it has to make sense
i am practising
tell me better wau to practise
is there a reference or resource
for this
you would pass the user input as an argument to GetShape
no need for abstract factory here
My second link got removed
I linked the other factory method pattern on that site as well
do u have things like problems to practise design patterns with @open ridge
if you have to ask, chances are you dont understand the pattern enough to make use of it
study on how the pattern is useful
i understand
when its 1 like 1 product
that can be divided into multiple implementations
each with their own behaviors
its a factory, like irl
true
you need to spawn some objects
ja
so you'd use a factory in situations where a factory would make sense, where you need to spawn many objects
constructors are strict, factories have flexibility
yeah, they hide the constructor usage
yup
is there a site for java problems
the factory could use a constructor. or maybe it uses IO. or maybe it uses reflection
depends on the type of problem
for code design, i dont know of any
for algorithms, there are tons
yup
Square seems to require some data
changed the null to throw an exception
true i was tinkering with it a bit
but ignore the square constructor missing the dimension
is this a good implementation
of a factoru
pattern
got a shape superclass interface
implemented bu 2 subclasses square and rectange
then a creator class
with the factoru method
The safer way to compare two strings is to use "square".equals(name), then you remove if(name == null)...
if you check name == null?it's no difference, so that's a safer way to avoid nullpointer exception
they're referring to doing "square".equalsIgnoreCase(name)
since "square" cant be null, you wont encounter an NPE
equalsIgnoreCase checks for null
ok thanks
that implementation is fine, very basic
hello want to make it
so when i do this method
the subscritption plan is cancelled
so it becomes null
is this a good wau
= null does not cancel the subscription.
it just changes the value of the local variable to null
the SubscriptionPlan object still exists
if you want to make some sort of cancellation, you need to change some state