본문 바로가기

eval3

1015. simple calculator You are required to create a simple calculator that returns the result of addition, subtraction, multiplication or division of two numbers. Your function will accept three arguments: The first and second argument should be numbers. The third argument should represent a sign indicating the operation to perform on these two numbers. if the variables are not numbers or the sign does not belong to t.. 2022. 10. 15.
0828. Basic Mathematical Operations Your task is to create a function that does four basic mathematical operations. The function should take three arguments - operation(string/char), value1(number), value2(number). The function should return result of numbers after applying the chosen operation. Examples(Operator, value1, value2) --> output ('+', 4, 7) --> 11 ('-', 15, 18) --> -3 ('*', 5, 5) --> 25 ('/', 49, 7) --> 7 Solution: def.. 2022. 8. 28.
심플 팩토리 패턴 팩토리 패턴 개요 팩토리란, 다른 클래스의 객체를 생성하는 클래스를 일컫는다. 클라이언트는 특정 ‘인자’와 함께 ‘메서드’를 호출하고 팩토리는 해당 객체를 생성하고 반환한다. 직접 객체를 생성하지 않고 팩토리를 사용하는 이유 객체 생성과 클래스 구현을 나눠 상호 의존도를 줄이기 위함. 클라이언트는 인터페이스와 메소드, 인자 등의 정보만 있으면 된다. 코드를 수정하지 않고 팩토리에 새로운 클래스를 추가할 수 있다. 이미 생성된 객체를 팩토리가 재활용할 수 있다. 팩토리 패턴 3가지 종류 심플 팩토리 패턴 - 인터페이스는 객체 생성 로직을 숨기고 객체를 생성 팩토리 메소드 패턴 - 인터페이스를 통해 객체를 생성하지만 서브 클래스가 객체 생성에 필요한 클래스를 선택 추상 팩토리 패턴 - 객체 생성에 필요한 클.. 2022. 5. 27.