# How to initialize CLASS by it's own function?

**URL:** <https://discourse.processing.org/t/how-to-initialize-class-by-its-own-function/23946>\
**Category:** Coding Questions\
**Created:** [September 18, 2020, 10:17pm UTC](https://discourse.processing.org/t/how-to-initialize-class-by-its-own-function/23946 "2020-09-18T22:17:28Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 19, 2020, 2:19am UTC](https://discourse.processing.org/t/how-to-initialize-class-by-its-own-function/23946/2 "2020-09-19T02:19:43Z")

</div>

The method Drop::**reachedBottom3()** returns a Drop object but you don’t do anything with it.

BtW, the method can be shortened to 1 `return` statement:

```auto
Drop reachedBottom3(final Drop self) {
  return y > height + r? new Drop() : self;
}

```

You need to reassign the returned Drop object back to the array:  
`drops[i] = drops[i].reachedBottom3(drops[i]);`

However that’s pretty awkward b/c the Drop object should be able to restart by its own w/o the caller having to do anything.

Instead you should define a method that **respawn()** the Drop’s fields back to their constructor values.

Basically you move anything inside Drop’s constructor to that separate method and invoke it inside the constructor instead.

And within method **move()** check whether field _y_ has reached the bottom and invoke **respawn()** if so.

Here’s the refactoring I did to your sketch. Check it out:  
https://www.openprocessing.org/sketch/965902/embed/?

Another similar sketch called “Raining Cloud”:  
`http://Studio.ProcessingTogether.com/sp/pad/export/ro.9l84$2z--gWui`

---

_[View the full topic](https://discourse.processing.org/t/how-to-initialize-class-by-its-own-function/23946)._
