Optimizing Code: Logging, Assertions, Exceptions, and Design Principles

warning n.w
1 / 7
Embed
Share

Explore the nuances of logging, assertions, exceptions, defensiveness, coupling, and cohesion in code. Delve into the impact of using assertions, handling exceptions, and maintaining optimal design principles. Understand the implications of defensive coding practices and effective logging strategies for better code structure.

  • Code Optimization
  • Error Handling
  • Design Principles
  • Software Development
  • Java

Uploaded on | 2 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010. They may not show up well on other PowerPoint versions. You can download PowerPoint 2010 viewer from here. These slides contain a lot of animations. For optimal results, watch in slideshow mode.

  2. Comment on logging, assertions, exceptions, defensiveness, coupling, and cohesion of this code (possible exam question). /* Sets user as active on the server. * @throws CannotActivateException if the user does not exist * on the server */ void activateUserOnServer(String userName) throws CannotActivateException{ log("trying to activate"); 1 assert isUsernameAcceptable(userName); 2 ServerConnection.activate(userName); if(!ServerConnection.isActivated(userName)) { throw new CannotActivateException(userName + " not activated"); } 3 4 5 6 Account account = AccountManager.getAccount(userName); account.toggleActivatedStatus(); //mark as activated 7 8 } What will happen in run time if name is invalid and assertions are enabled? Is it right to use assertions here? Does the behavior match the header comment? Is this a correct use of exceptions? Does it match the header comment? How does this affect coupling and cohesion? Is this defensive enough? Is this a good log message? ---

  3. Procedural Boil water Put tea leaves in strainer Add hot water Steep for a while Remove strainer Add milk and sugar OOP 1 chef 2 waiters 1 cashier 1 part time accountant 1 manager 1 cash register 1 stove Serve tea Clean table Toast bread Cut bread Accept payment Give change Issue receipt Wash utensils Pay bills Order supplies

  4. OOP Architecture 1 chef 2 waiters 1 cashier 1 part time accountant 1 manager 1 cash register 1 stove Divisions/Departments Kitchen Accounting Customer Services Purchasing

  5. OOP Architecture

  6. OOP Architecture

  7. Architecture B A D C Achievement Unlocked! Multi-level design :A :B :D OOP Component design Component A design Component C design A C * B * D C Component B design Component D design

Related


More Related Content