Coder Social home page Coder Social logo

phantomcase / short-exercise-oop-encapsulation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from techreturners/short-exercise-oop-encapsulation

0.0 1.0 0.0 23 KB

This is a short exercise using the example of bank accounts to demonstrate the importance of encapsulation

License: GNU General Public License v3.0

Java 100.00%

short-exercise-oop-encapsulation's Introduction

A Short Exercise to Explore Object-Oriented Programming - Encapsulation


Overview

This repository is a short exercise designed for you to explore Encapsulation which is one of the four pillars of Object-Oriented Programming (OOP).


๐Ÿ“– Instructions

  • Fork this repository

  • To run the program, go to the Main class which is the entry point and run it using IntelliJ

  • There are two models DodgyBankAccount and SecureBankAccount, these are located in the model directory.


๐Ÿค“ Study Prompts

Use the following questions to guide your exploration and learning! ๐Ÿ—บ

  • Run the main method on the Main class, what is it doing? What is being outputted to the console?

  • Look at the DodgyBankAccount, this class is not well-encapsulated. Can you note down the problems with how the class is designed, and the ways it is being misused?

  • Compare and contrast the DodgyBankAccount and the SecureBankAccount, how is the SecureBankAccount different to the DodgyBankAccount? How is it designed to prevent it from being misused? Are there instances of better method names for clearer abstraction?


๐Ÿธ Extension Challenge

  • Now that you've had the chance to explore a well-encapsulated vs. poorly-encapsulated class, your next challenge is to put your newly minted skills into practice ๐Ÿ’ช!

  • Refactor the WeatherReporter class located in the model directory.

  • You may want to think about Encapsulation here. Do the methods follow the Single Responsibility Principle (SRP)? Are the method names suitable? Are there any magic numbers / hardcoded numbers in the code that needs to be represented by a constant? Are there better ways to write the code?

  • As an added challenge, could you write some unit tests to test the class' methods?

short-exercise-oop-encapsulation's People

Contributors

eggsy84 avatar kimdiep avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.