Skip to content

Commit af4fe85

Browse files
committed
adding methodsAndFunctions.tx file
1 parent 9f25002 commit af4fe85

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Advantages of Using Methods Instead of Free Functions
2+
# Easier to maintain
3+
Methods keep related operations inside the class, making the program more organized and easier to update.
4+
# Better data protection
5+
A method can control how the object's data is changed and prevent invalid changes.
6+
# Simple to use
7+
Methods can be called using dot notation, such as account.deposit(100), which makes the code easy to read.
8+
# Hides unnecessary details
9+
Users only need to know what a method does and how to call it. They don't need to understand all the code inside it.
10+
# Keeps data and behaviour together
11+
A class can contain both the information about an object and the methods that work with that information.
12+
# Can be reused with different objects
13+
Once a method is defined in a class, objects created from that class can use the same method.
14+
# Allows rules to be enforced
15+
Methods can make sure that data is changed in a safe and valid way. For example, a withdraw() method could prevent a bank account from having a negative balance.
16+
In short: methods are useful because they make code more organized,
17+
reusable, easier to understand, and safer to manage, especially when working with objects and their data.

0 commit comments

Comments
 (0)