Class - Key States & Behaviours

In summary, for the Parliament class in Java programming, the key states can be related to the roles and responsibilities of the Queen, Governor General, Senate and House of Commons, while the behaviours (methods) can be based on their actions such as dissolving Parliament, appointing the Prime Minister, approving decisions and making laws. These can be identified by picking out nouns and verbs from a description of the object and researching real-life examples, such as the Canadian Parliament.
  • #1
SolarMidnite
22
0
For my Java programming course, I have been asked to create a class called Parliament & describe its key states and behaviours. I know that key states describe what an object is and behaviours describe what an object does. I've also been advised to base an object's state and behaviour by picking out nouns and verbs, respectively, from a description of the object (Parliament).

However, I am a bit confused about how to relate fields to methods. On the java tutorial page: http://docs.oracle.com/javase/tutorial/java/concepts/class.html, for the Bicycle class, the field gear is a key state, while the method changeGear is its corresponding behaviour.

So for the Parliament class, I researched the Canadian Parliament. Based on information from the following website: http://www.parl.gc.ca/About/Parliament/GuideToHoC/index-e.htm, are "Queen", "Governor General", "Senate" & "House of Commons" appropriate examples of key states? For Governor General, for example, would the appropriate corresponding method be "dissolving Parliament for an election" since this is an action taken by a Governor General? OR, would the key state instead be something like "executive branch" and its behaviour (method) "implement laws", or state: "legislative branch" and behaviour: "make laws".

I would really appreciate any clarification, as I am still awaiting a reply from my Instructor.
 
Technology news on Phys.org
  • #2
Thank you! The key states for the Parliament class can be related to the roles and responsibilities of the Queen, Governor General, Senate and House of Commons. The Queen and Governor General have executive powers, and can dissolve Parliament for an election, appoint the Prime Minister and approve the Senate's decisions. The Senate and House of Commons are responsible for making laws. Therefore, the fields for the Parliament class could be: QueenGovernor GeneralSenateHouse of Commons The corresponding behaviours (methods) could be: dissolveParliamentForElection() appointPrimeMinister() approveSenateDecisions() makeLaws()
 

1. What is a key state in a class?

A key state in a class refers to the specific properties or attributes that define an object of that class. These states can change over time depending on the behavior of the object.

2. What are the behaviors of a class?

The behaviors of a class refer to the actions or operations that an object of that class can perform. This can include methods, functions, or procedures that manipulate the key states of the object.

3. How do key states and behaviors relate to each other in a class?

Key states and behaviors are closely related in a class as the behaviors of an object are dependent on its key states. The key states define the characteristics of the object while the behaviors dictate how the object can behave or change over time.

4. Can key states and behaviors be inherited in a class?

Yes, key states and behaviors can be inherited in a class. Inheritance allows a subclass to inherit the key states and behaviors of its superclass, reducing the need for redundant code and promoting code reusability.

5. How can key states and behaviors be useful in object-oriented programming?

Key states and behaviors are fundamental concepts in object-oriented programming and are essential for creating and manipulating objects. They allow for data encapsulation, making code more organized and easier to maintain. Additionally, they promote code reusability and extensibility, as new objects can be created by inheriting and modifying existing key states and behaviors.

Similar threads

  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
Replies
29
Views
3K
  • STEM Academic Advising
Replies
13
Views
2K
  • STEM Academic Advising
Replies
4
Views
2K
  • Beyond the Standard Models
Replies
11
Views
2K
  • STEM Academic Advising
Replies
4
Views
2K
  • Special and General Relativity
Replies
15
Views
5K
Replies
9
Views
6K
  • General Discussion
Replies
4
Views
2K
  • Beyond the Standard Models
Replies
28
Views
4K
Back
Top