# Can event handler within function count as an abstraction?

**URL:** <https://forum.code.org/t/can-event-handler-within-function-count-as-an-abstraction/15200>\
**Category:** CS Principles\
**Created:** [March 22, 2018, 6:18pm UTC](https://forum.code.org/t/can-event-handler-within-function-count-as-an-abstraction/15200 "2018-03-22T18:18:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![agrant](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/agrant/32/5651_2.png) [@agrant](https://forum.code.org/u/agrant)\
**Post date:** [March 22, 2018, 6:18pm UTC](https://forum.code.org/t/can-event-handler-within-function-count-as-an-abstraction/15200/1 "2018-03-22T18:18:18Z")

</div>

I have a student that is working on the Create task and created a function that includes an onEvent handler. It says in the Survival Guide to avoid using event handlers since they are not student-developed abstractions, but what if the event handler is part of a larger student developed function?

---

<div class="post-metadata">

**Author:** ![bhatnagars](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bhatnagars/32/4919_2.png) [@bhatnagars](https://forum.code.org/u/bhatnagars)\
**Post date:** [March 22, 2018, 7:35pm UTC](https://forum.code.org/t/can-event-handler-within-function-count-as-an-abstraction/15200/2 "2018-03-22T19:35:23Z")

</div>

An event handler should never be put inside a function. The eventhandler is triggered (called) each time the event occurs. Here is a link to some more discussion on event handlers.

> **[OnEvent within another onEvent allowed?](https://forum.code.org/t/onevent-within-another-onevent-allowed/15025/2?u=bhatnagars)**
>
> I have a student that wants to provide the option of two different type of games in the Clicker App - if the user clicks catButton, then the game behaves one way, and if dogButton, another way. She attempted this with two different functions: a...

---

<div class="post-metadata">

**Author:** ![agrant](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/agrant/32/5651_2.png) [@agrant](https://forum.code.org/u/agrant)\
**Post date:** [March 23, 2018, 11:40pm UTC](https://forum.code.org/t/can-event-handler-within-function-count-as-an-abstraction/15200/3 "2018-03-23T23:40:33Z")

</div>

That makes sense - thank you!

---

<div class="post-metadata">

**Author:** ![jbailey](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jbailey/32/6903_2.png) [@jbailey](https://forum.code.org/u/jbailey)\
**Post date:** [April 4, 2018, 1:33pm UTC](https://forum.code.org/t/can-event-handler-within-function-count-as-an-abstraction/15200/4 "2018-04-04T13:33:29Z")

</div>

So is it accurate advice to say to students that their Create Task can have onEvent as long as they don’t claim it as their “student created” abstraction/algorithm or should OnEvent not appear in the code anywhere?

---

<div class="post-metadata">

**Author:** ![baker](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/baker/32/1229_2.png) [@baker](https://forum.code.org/u/baker)\
**Post date:** [April 4, 2018, 2:17pm UTC](https://forum.code.org/t/can-event-handler-within-function-count-as-an-abstraction/15200/5 "2018-04-04T14:17:01Z")

</div>

The former. onEvent can’t be the abstraction. The litmus test is: is it a _named_ function that the student wrote. What the reader is looking for is - did the student have an insight to develop an abstraction (i.e. function) because it was something that could be reused, or because it helped manage the complexity of the task.

If you look to the exemplars of the color sleuth project in Unit 5 Lesson 10 you’ll see some examples and commentary about this.

Also, if you haven’t, you should really check out the Create PT survival guide. In the [Create PT prep mini-unit](https://studio.code.org/s/csp-create/stage/2/puzzle/1#) which has a lot of student-facing guidance and activities around this very subject.
